当前位置: 首页>>代码示例>>C#>>正文


C# Hashtable.ContainsValue方法代码示例

本文整理汇总了C#中Hashtable.ContainsValue方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.ContainsValue方法的具体用法?C# Hashtable.ContainsValue怎么用?C# Hashtable.ContainsValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hashtable的用法示例。


在下文中一共展示了Hashtable.ContainsValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCtorDictionarySingle

        public void TestCtorDictionarySingle()
        {
            // No exception
            var hash = new Hashtable(new Hashtable(), 1f);
            // No exception
            hash = new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable()), 1f), 1f), 1f), 1f);

            // []test to see if elements really get copied from old dictionary to new hashtable
            Hashtable tempHash = new Hashtable();
            // this for assumes that MinValue is a negative!
            for (long i = long.MinValue; i < long.MinValue + 100; i++)
            {
                tempHash.Add(i, i);
            }

            hash = new Hashtable(tempHash, 1f);

            // make sure that new hashtable has the elements in it that old hashtable had
            for (long i = long.MinValue; i < long.MinValue + 100; i++)
            {
                Assert.True(hash.ContainsKey(i));
                Assert.True(hash.ContainsValue(i));
            }

            //[]make sure that there are no connections with the old and the new hashtable
            tempHash.Clear();
            for (long i = long.MinValue; i < long.MinValue + 100; i++)
            {
                Assert.True(hash.ContainsKey(i));
                Assert.True(hash.ContainsValue(i));
            }
        }
开发者ID:sky7sea,项目名称:corefx,代码行数:32,代码来源:CtorTests.cs

示例2: TestAddBasic

        public void TestAddBasic()
        {
            Hashtable ht = null;
            string[] keys = { "key_0", "key_1"};
            string[] values = { "val_0", "val_1" };

            var k1 = new StringBuilder(keys[0]);
            var k2 = new StringBuilder(keys[1]);
            var v1 = new StringBuilder(values[0]);
            var v2 = new StringBuilder(values[1]);

            ht = new Hashtable();
            ht.Add(k1, v1);
            ht.Add(k2, v2);

            Assert.True(ht.ContainsKey(k2));
            Assert.True(ht.ContainsValue(v2));

            ICollection allkeys = ht.Keys;
            Assert.Equal(allkeys.Count, ht.Count);

            IEnumerator allkeysEnum = allkeys.GetEnumerator();
            int index = 0;
            string[] ary = new string[2];
            while (allkeysEnum.MoveNext())
            {
                ary[index++] = allkeysEnum.Current.ToString();
            }

            // Not necessary the same order
            if (keys[0] == ary[0])
            {
                Assert.Equal(keys[1], ary[1]);
            }
            else
            {
                Assert.Equal(keys[0], ary[1]);
            }

            ICollection allvalues = ht.Values;
            Assert.Equal(allvalues.Count, ht.Count);

            IEnumerator allvaluesEnum = allvalues.GetEnumerator();
            index = 0;
            while (allvaluesEnum.MoveNext())
            {
                ary[index++] = (string)allvaluesEnum.Current.ToString();
            }

            if (values[0] == ary[0])
            {
                Assert.Equal(values[1], ary[1]);
            }
            else
            {
                Assert.Equal(values[0], ary[1]);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:58,代码来源:AddTests.cs

示例3: TestClearBasic

        public void TestClearBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);
            Hashtable ht1 = null;
            string s1 = null;
            string s2 = null;

            int i = 0;
            ht1 = new Hashtable(); //default constructor
            ht1.Clear();

            Assert.Equal(0, ht1.Count);

            // add 100 key-val pairs
            ht1 = new Hashtable();

            for (i = 0; i < 100; i++)
            {
                sblMsg = new StringBuilder(99);
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();

                sblMsg = new StringBuilder(99);
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                ht1.Add(s1, s2);
            }

            Assert.Equal(100, ht1.Count);
            ht1.Clear();

            Assert.Equal(0, ht1.Count);

            //[]we will make a token call for some important methods to make sure that this is indeed clear
            s1 = "key_0";
            Assert.False(ht1.ContainsKey(s1));

            s1 = "val_0";
            Assert.False(ht1.ContainsValue(s1));

            //[]repeated clears of the HT. Nothing should happen		

            for (i = 0; i < 100; i++)
            {
                ht1.Clear();

                Assert.Equal(0, ht1.Count);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:52,代码来源:ClearTests.cs

示例4: TestCtorIntSingle

        public void TestCtorIntSingle()
        {
            // variables used for tests
            Hashtable hash = null;

            // [] should get ArgumentException if trying to have large num of entries
            Assert.Throws<ArgumentException>(() =>
            {
                hash = new Hashtable(int.MaxValue, .1f);
            }
            );

            // []should not get any exceptions for valid values - we also check that the HT works here
            hash = new Hashtable(100, .1f);

            int iNumberOfElements = 100;
            for (int i = 0; i < iNumberOfElements; i++)
            {
                hash.Add("Key_" + i, "Value_" + i);
            }

            //Count
            Assert.Equal(hash.Count, iNumberOfElements);

            DictionaryEntry[] strValueArr = new DictionaryEntry[hash.Count];
            hash.CopyTo(strValueArr, 0);

            Hashtable hsh3 = new Hashtable();
            for (int i = 0; i < iNumberOfElements; i++)
            {
                Assert.True(hash.Contains("Key_" + i), "Error, Expected value not returned, " + hash.Contains("Key_" + i));
                Assert.True(hash.ContainsKey("Key_" + i), "Error, Expected value not returned, " + hash.ContainsKey("Key_" + i));
                Assert.True(hash.ContainsValue("Value_" + i), "Error, Expected value not returned, " + hash.ContainsValue("Value_" + i));

                //we still need a way to make sure that there are all these unique values here -see below code for that
                Assert.True(hash.ContainsValue(((DictionaryEntry)strValueArr[i]).Value), "Error, Expected value not returned, " + ((DictionaryEntry)strValueArr[i]).Value);

                hsh3.Add(((DictionaryEntry)strValueArr[i]).Value, null);
            }
        }
开发者ID:sky7sea,项目名称:corefx,代码行数:40,代码来源:CtorTests.cs

示例5: TestGetSyncRootBasic

        public void TestGetSyncRootBasic()
        {
            Hashtable arrSon;
            Hashtable arrMother;

            Task[] workers;
            Action ts1;
            Action ts2;
            Int32 iNumberOfWorkers = 30;
            Hashtable hshPossibleValues;
            IDictionaryEnumerator idic;

            Hashtable hsh1;
            Hashtable hsh2;
            Hashtable hsh3;

            //[] we will create different HT and make sure that they return different SyncRoot values
            hsh1 = new Hashtable();
            hsh2 = new Hashtable();

            Assert.NotEqual(hsh1.SyncRoot, hsh2.SyncRoot);
            Assert.Equal(hsh1.SyncRoot.GetType(), typeof(object));

            //[] a clone of a Syncronized HT should not be pointing to the same SyncRoot
            hsh1 = new Hashtable();
            hsh2 = Hashtable.Synchronized(hsh1);
            hsh3 = (Hashtable)hsh2.Clone();

            Assert.NotEqual(hsh2.SyncRoot, hsh3.SyncRoot);

            Assert.NotEqual(hsh1.SyncRoot, hsh3.SyncRoot);

            //[] testing SyncRoot is not as simple as its implementation looks like. This is the working
            //scenrio we have in mind.
            //1) Create your Down to earth mother Hashtable
            //2) Get a synchronized wrapper from it
            //3) Get a Synchronized wrapper from 2)
            //4) Get a synchronized wrapper of the mother from 1)
            //5) all of these should SyncRoot to the mother earth

            arrMother = new Hashtable();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                arrMother.Add("Key_" + i, "Value_" + i);
            }

            arrSon = Hashtable.Synchronized(arrMother);
            _arrGrandDaughter = Hashtable.Synchronized(arrSon);
            _arrDaughter = Hashtable.Synchronized(arrMother);

            Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);
            Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);
            Assert.Equal(_arrGrandDaughter.SyncRoot, arrMother.SyncRoot);
            Assert.Equal(_arrDaughter.SyncRoot, arrMother.SyncRoot);
            Assert.Equal(arrSon.SyncRoot, arrMother.SyncRoot);

            //we are going to rumble with the Hashtables with some threads
            workers = new Task[iNumberOfWorkers];
            ts2 = new Action(RemoveElements);
            for (int iThreads = 0; iThreads < iNumberOfWorkers; iThreads += 2)
            {
                var name = "Thread_worker_" + iThreads;
                ts1 = new Action(() => AddMoreElements(name));

                workers[iThreads] = Task.Run(ts1);
                workers[iThreads + 1] = Task.Run(ts2);
            }

            Task.WaitAll(workers);

            //checking time
            //Now lets see how this is done.
            //Either there should be some elements (the new ones we added and/or the original ones) or none
            hshPossibleValues = new Hashtable();
            for (int i = 0; i < _iNumberOfElements; i++)
            {
                hshPossibleValues.Add("Key_" + i, "Value_" + i);
            }

            for (int i = 0; i < iNumberOfWorkers; i++)
            {
                hshPossibleValues.Add("Key_Thread_worker_" + i, "Thread_worker_" + i);
            }

            idic = arrMother.GetEnumerator();

            while (idic.MoveNext())
            {
                Assert.True(hshPossibleValues.ContainsKey(idic.Key), "Error, Expected value not returned, " + idic.Key);
                Assert.True(hshPossibleValues.ContainsValue(idic.Value), "Error, Expected value not returned, " + idic.Value);
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:92,代码来源:PropertySyncRootTests.cs

示例6: runTest

 public Boolean runTest()
 {
     Console.WriteLine( s_strTFPath +" "+ s_strTFName +" ,for "+ s_strClassMethod +"  ,Source ver "+ s_strDtTmVer );
     String strLoc = "Loc_000oo";
     Hashtable hash = null;
     int iCountErrors    = 0;                      
     int iCountTestcases = 0;                      
     strLoc = "Loc_001oo";
     try
     {
         ++iCountTestcases;
         hash = new Hashtable( Int32.MaxValue, .1f, null, null );
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_0001!  hashtable should have thrown ArgumentException here" );
     }
     catch( ArgumentException )
     {
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1001!  we expected ArgumentException but got exception " + ex.ToString() );
     }
     try
     {
         ++iCountTestcases;
         hash = new Hashtable( 100, .1f, null, null );
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1002!  we expected no exception but got exception " + ex.ToString() );
     }
     Int32 iNumberOfElements = 100;
     for(int i=0; i<iNumberOfElements; i++)
     {
         hash.Add("Key_" + i, "Value_" + i);
     }
     iCountTestcases++;
     if(hash.Count != iNumberOfElements) 
     {
         iCountErrors++;
         Console.WriteLine("Err_742dsf! Expected value not returned, " + hash.Count);
     }				
     DictionaryEntry[] strValueArr = new DictionaryEntry[hash.Count];
     hash.CopyTo(strValueArr, 0);
     Hashtable hsh3 = new Hashtable();
     for(int i=0; i<iNumberOfElements; i++)
     {
         if(!hash.Contains("Key_" + i)) 
         {
             iCountErrors++;
             Console.WriteLine("Err_742ds8f! Expected value not returned, " + hash.Contains("Key_" + i));
         }				
         if(!hash.ContainsKey("Key_" + i)) 
         {
             iCountErrors++;
             Console.WriteLine("Err_742389dsaf! Expected value not returned, " + hash.ContainsKey("Key_" + i));
         }				
         if(!hash.ContainsValue("Value_" + i)) 
         {
             iCountErrors++;
             Console.WriteLine("Err_563fgd! Expected value not returned, " + hash.ContainsValue("Value_" + i));
         }				
         if(!hash.ContainsValue(((DictionaryEntry)strValueArr[i]).Value)) 
         {
             iCountErrors++;
             Console.WriteLine("Err_87429dsfd! Expected value not returned, " + ((DictionaryEntry)strValueArr[i]).Value);
         }				
         try
         {
             hsh3.Add(((DictionaryEntry)strValueArr[i]).Value, null);
         }
         catch(Exception)
         {
             iCountErrors++;
             Console.WriteLine("Err_74298dsd! Exception thrown for  " + ((DictionaryEntry)strValueArr[i]).Value);
         }
     }
     try
     {
         ++iCountTestcases;
         hash = new Hashtable( 5, .01f, null, null );
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_0003!  hashtable should have thrown ArgumentOutOfRangeException  here" );
     }
     catch( ArgumentOutOfRangeException  )
     {
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1003!  we expected ArgumentOutOfRangeException  but got exception " + ex.ToString() );
     }
     try
     {
         ++iCountTestcases;
         hash = new Hashtable( 5, 100.1f, null, null );
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_0004!  hashtable should have thrown ArgumentOutOfRangeException  here" );
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co1659ctor_ifii.cs

示例7: TestContainsValueBasic

        public void TestContainsValueBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);

            Hashtable ht1 = null;

            string s1 = null;
            string s2 = null;

            ht1 = new Hashtable(); //default constructor
            Assert.False(ht1.ContainsValue("No_Such_Val"));

            /// add few key-val pairs
            ht1 = new Hashtable();
            for (int i = 0; i < 100; i++)
            {
                sblMsg = new StringBuilder(99);
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();

                sblMsg = new StringBuilder(99);
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                ht1.Add(s1, s2);
            }

            for (int i = 0; i < ht1.Count; i++)
            {
                sblMsg = new StringBuilder(99);
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();


                Assert.True(ht1.ContainsValue(s2));
            }

            //
            // Remove a key and then check
            //
            sblMsg = new StringBuilder(99);
            sblMsg.Append("key_50");
            s1 = sblMsg.ToString();

            ht1.Remove(s1); //removes "Key_50"

            sblMsg = new StringBuilder(99);
            sblMsg.Append("val_50");
            s2 = sblMsg.ToString();

            Assert.False(ht1.ContainsValue(s2));

            //
            // Look for a null element after two element have been added with the same hashcode then one removed
            //
            sblMsg = new StringBuilder(99);
            sblMsg.Append("key_50");
            s1 = sblMsg.ToString();

            ht1 = new Hashtable();
            int i1 = 0x10;
            int i2 = 0x100;
            long l1 = (((long)i1) << 32) + i2;// create two longs with same hashcode
            long l2 = (((long)i2) << 32) + i1;
            string str1 = "string 1";

            object o1 = l1;
            object o2 = l2;
            ht1.Add(o1, str1);
            ht1.Add(o2, str1);      // this will cause collision bit of the first entry to be set
            ht1.Remove(o1);         // remove the first item, the hashtable should not

            // contain null value
            Assert.False(ht1.ContainsValue(0));

            //
            // Look for a null element when the collection contains a null element
            //
            ht1 = new Hashtable();
            for (int i = 0; i < 256; i++)
            {
                ht1.Add(i.ToString(), i);
            }

            ht1.Add(ht1.Count.ToString(), 0);
            Assert.True(ht1.ContainsValue(0));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:90,代码来源:ContainsValueTests.cs

示例8: runTest


//.........这里部分代码省略.........
             iCountTestcases++;
             if(arrSon.SyncRoot != arrMother.SyncRoot) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_234dnvf! Expected value not returned, " + (arrSon.SyncRoot==arrMother.SyncRoot));
             }
             iCountTestcases++;
             if(arrSon.SyncRoot!=arrMother) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_8230fvbd! Expected value not returned, " + (arrSon.SyncRoot==arrMother));
             }
             iCountTestcases++;
             if(arrGrandDaughter.SyncRoot!=arrMother) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_4927fd0fd! Expected value not returned, " + (arrGrandDaughter.SyncRoot==arrMother));
             }
             iCountTestcases++;
             if(arrDaughter.SyncRoot!=arrMother) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_85390gfg! Expected value not returned, " + (arrDaughter.SyncRoot==arrMother));
             }
             iCountTestcases++;
             if(arrSon.SyncRoot != arrMother.SyncRoot) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_234dnvf! Expected value not returned, " + (arrSon.SyncRoot==arrMother.SyncRoot));
             }
             strLoc = "Loc_845230fgdg";
             workers = new Thread[iNumberOfWorkers];
             ts1 = new ThreadStart(AddMoreElements);
             ts2 = new ThreadStart(RemoveElements);
             for(int iThreads=0; iThreads<iNumberOfWorkers;iThreads+=2)
             {
                 strLoc = "Loc_74329fd_" + iThreads;
                 workers[iThreads] = new Thread(ts1);
                 workers[iThreads].Name = "Thread_worker_" + iThreads;
                 workers[iThreads+1] = new Thread(ts2);
                 workers[iThreads+1].Name = "Thread_worker_" + iThreads + 1;
                 workers[iThreads].Start();
                 workers[iThreads+1].Start();
             }
         while(true)
         {
             fLoopExit=false;
             for(int i=0; i<iNumberOfWorkers;i++)
             {
                 if(workers[i].IsAlive)
                     fLoopExit=true;
             }
             if(!fLoopExit)
                 break;
         }
             strLoc = "Loc_7539vfdg";
             iCountTestcases++;
             hshPossibleValues = new Hashtable();
             for(int i=0; i<iNumberOfElements; i++)
             {
                 hshPossibleValues.Add("Key_" + i, "Value_" + i);
             }
             for(int i=0; i<iNumberOfWorkers; i++)
             {
                 hshPossibleValues.Add("Key_Thread_worker_" + i, "Thread_worker_" + i);
             }
             if(arrMother.Count>0)
                 Console.WriteLine("Loc_7428fdsg! Adds have it");
             idic = arrMother.GetEnumerator();
         while(idic.MoveNext())
         {
             if(!hshPossibleValues.ContainsKey(idic.Key))
             {
                 iCountErrors++;
                 Console.WriteLine("Err_7429dsf! Expected value not returned, " + idic.Key);
             }
             if(!hshPossibleValues.ContainsValue(idic.Value))
             {
                 iCountErrors++;
                 Console.WriteLine("Err_2487dsf! Expected value not returned, " + idic.Value);
             }
         }
         } while (false);
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co3944get_syncroot.cs

示例9: runTest

 public Boolean runTest
     (
     int p_inLoops0  
     ,int p_inLoops1
     )
 {
     Console.Error.WriteLine( "Co4310Add_Stress  runTest(stress/perf) started." );
     String strLoc="Loc_000oo";
     StringBuilder sblMsg = new StringBuilder( 99 );
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Hashtable ht2 = null;
     Hashtable ht = null;
     StringBuilder sbl3 = new StringBuilder( 99 );
     StringBuilder sbl4 = new StringBuilder( 99 );
     StringBuilder sbl5 = new StringBuilder( 99 );
     StringBuilder sblWork1 = new StringBuilder( 99 );
     StringBuilder k1 = new StringBuilder(99);
     StringBuilder k2 = new StringBuilder(99);
     StringBuilder v1 = new StringBuilder(99);
     StringBuilder v2 = new StringBuilder(99);
     String str5 = null;
     String str6 = null;
     String str7 = null;
     int[] in4a = new int[9];
     int[] in4TickCount = new int[9];
     int inTCIdx = 0;
     try
     {
         do
         {
             in4TickCount[inTCIdx++] = Environment.TickCount;
             if ( p_inLoops0 < 2 )
                 p_inLoops0 = 2;
             if ( p_inLoops1 < 2 )
                 p_inLoops1 = 2;
             Console.Error.WriteLine( "Info Inf_201pa.  parms are: " + p_inLoops0 + " ," + p_inLoops1 );
             strLoc="10cc";
             iCountTestcases++;
             k1 = new StringBuilder("key_0");
             k2 = new StringBuilder("key_1");
             v1 = new StringBuilder("val_0");
             v2 = new StringBuilder("val_1");
             ht = new Hashtable();
             ht.Add (k1, v1);
             ht.Add (k2, v2);
             strLoc="20cc";
             iCountTestcases++;
             if (!ht.ContainsKey (k2)) 
             {
                 ++iCountErrors;
                 Console.Error.WriteLine(  "POINTTOBREAK: Error Err_287!  "  );
             }
             strLoc="30cc";
             iCountTestcases++;
             if (!ht.ContainsValue (v2)) 
             {
                 ++iCountErrors;
                 Console.Error.WriteLine(  "POINTTOBREAK: Error Err_348!  "  );
             }
             strLoc="40cc";
             iCountTestcases++;
             try 
             {
                 ICollection allkeys = ht.Keys;
                 if (allkeys.Count != ht.Count) 
                 {
                     ++iCountErrors;
                     Console.Error.WriteLine(  "POINTTOBREAK: Error Err_892!  "  );
                 }
                 IEnumerator allkeysEnum = allkeys.GetEnumerator();
                 while ( allkeysEnum.MoveNext() )
                 {
                     String strTemp = allkeysEnum.Current.ToString();
                 }
             }
             catch (Exception exc) 
             {
                 ++iCountErrors;
                 Console.Error.WriteLine(  "POINTTOBREAK: Error Err_2yi!  exc==" + exc  );
             }
             strLoc="50cc";
             iCountTestcases++;
             try 
             {
                 ICollection allvalues  = ht.Values; 
                 if (allvalues.Count != ht.Count) 
                 {
                     ++iCountErrors;
                     Console.Error.WriteLine(  "POINTTOBREAK: Error Err_892!  "  );
                 }
                 IEnumerator allvaluesEnum = allvalues.GetEnumerator();
                 while( allvaluesEnum.MoveNext() )
                 {
                     String strTemp = (String) allvaluesEnum.Current.ToString();
                 }
             }
             catch (Exception exc) 
             {
                 ++iCountErrors;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co4310add_stress.cs

示例10: btnUpdateSeq_Click

    protected void btnUpdateSeq_Click(object sender, EventArgs e)
    {
        Hashtable htList = new Hashtable();

        for (int i = 0; i < gridViewCSList.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (gridViewCSList.Rows[i].RowType == DataControlRowType.DataRow)
            {
                string FtID = gridViewCSList.Rows[i].Cells[0].Text.ToString();
                TextBox tbBox = (TextBox)gridViewCSList.Rows[i].FindControl("txtSeqList");

                if (!checkNum(tbBox.Text.Trim()))
                {
                    messageContent.InnerHtml = GetLocalResourceObject("UpdateError1").ToString();
                    return;
                }

                htList.Add(FtID, tbBox.Text);
            }
        }

        Hashtable hNew = new Hashtable();
        foreach (System.Collections.DictionaryEntry key in htList)
        {
            if (!hNew.ContainsValue(key.Value)) hNew.Add(key.Key, key.Value);
        }

        if (hNew.Values.Count != htList.Values.Count)
        {
            messageContent.InnerHtml = GetLocalResourceObject("UpdateError2").ToString();
            return;
        }

        _hotelfacilitiesEntity.HotelFacilitiesDBEntity = new List<HotelFacilitiesDBEntity>();

        _hotelfacilitiesEntity.LogMessages = new HotelVp.Common.Logger.LogMessage();
        _commonEntity.LogMessages = new HotelVp.Common.Logger.LogMessage();
        _hotelfacilitiesEntity.LogMessages.Userid = UserSession.Current.UserAccount;
        _hotelfacilitiesEntity.LogMessages.Username = UserSession.Current.UserDspName;
        _hotelfacilitiesEntity.LogMessages.IpAddress = UserSession.Current.UserIP;
        _hotelfacilitiesEntity.HotelFacilitiesDBEntity = new List<HotelFacilitiesDBEntity>();

        HotelFacilitiesDBEntity hotelFacilitiesDBEntity = new HotelFacilitiesDBEntity();
        hotelFacilitiesDBEntity.FTSeqList = htList;
        _hotelfacilitiesEntity.HotelFacilitiesDBEntity.Add(hotelFacilitiesDBEntity);

        int iResult = HotelFacilitiesBP.FtTypeSeqListUpdate(_hotelfacilitiesEntity);
        _commonEntity.LogMessages = _hotelfacilitiesEntity.LogMessages;
        _commonEntity.CommonDBEntity = new List<CommonDBEntity>();
        CommonDBEntity commonDBEntity = new CommonDBEntity();

        commonDBEntity.Event_Type = "服务设施类别管理-排序修改";
        commonDBEntity.Event_ID = "";
        string conTent = "";
        conTent = GetLocalResourceObject("EventUpdateMessageSeq").ToString();
        //conTent = string.Format(conTent, txtFtCode.Value, txtFtName.Value, lbFtSeq.Text, ddpStatusList.SelectedValue);
        commonDBEntity.Event_Type = "";
        commonDBEntity.Event_ID = "";
        commonDBEntity.Event_Content = conTent;

        if (iResult == 1)
        {
            messageContent.InnerHtml = GetLocalResourceObject("UpdateSuccessSeq").ToString();
            commonDBEntity.Event_Result = GetLocalResourceObject("UpdateSuccessSeq").ToString();
            BindFtListGrid();
        }
        else
        {
            messageContent.InnerHtml = GetLocalResourceObject("UpdateError").ToString();
            commonDBEntity.Event_Result = GetLocalResourceObject("UpdateError").ToString();
        }

        foreach (System.Collections.DictionaryEntry key in htList)
        {
            conTent = string.Format(conTent, key.Key, key.Value);
            _commonEntity.CommonDBEntity.Add(commonDBEntity);
            CommonBP.InsertEventHistory(_commonEntity);
        }
    }
开发者ID:WuziyiaoKingIris20140501,项目名称:KFC,代码行数:80,代码来源:FacilitiesTypeSearchPage.aspx.cs

示例11: TestGetEnumeratorBasic

        public void TestGetEnumeratorBasic()
        {
            Hashtable hash1;
            IDictionaryEnumerator dicEnum1;
            int ii;
            string str1;

            string strRetKey;
            int iExpValue;

            Queue que1;
            Queue que2;

            //[] 1) Empty Hash table
            //Get enumerator for an empty table
            hash1 = new Hashtable();
            dicEnum1 = hash1.GetEnumerator();

            Assert.Equal(dicEnum1.MoveNext(), false);

            //[] 2) Full hash table
            hash1 = new Hashtable();
            for (ii = 0; ii < 100; ii++)
            {
                str1 = string.Concat("key_", ii.ToString());
                hash1.Add(str1, ii);
            }

            dicEnum1 = hash1.GetEnumerator();

            ii = 0;
            //Enumerator (well, Hashtable really) does not hold values in the order we put them in!!
            //so we will use 2 ques to confirm that all the keys and values we put inside the hashtable was there
            que1 = new Queue();
            que2 = new Queue();

            while (dicEnum1.MoveNext() != false)
            {
                strRetKey = (string)dicEnum1.Key;
                iExpValue = Convert.ToInt32(dicEnum1.Value);

                //we make sure that the values are there
                Assert.True(hash1.ContainsKey(strRetKey));
                Assert.True(hash1.ContainsValue(iExpValue));

                //we will make sure that enumerator get all the objects
                que1.Enqueue(strRetKey);
                que2.Enqueue(iExpValue);
            }

            //making sure the que size is right
            Assert.Equal(100, que1.Count);
            Assert.Equal(100, que2.Count);

            // 3) Full hash table, allow remove true

            hash1 = new Hashtable();
            for (ii = 0; ii < 100; ii++)
            {
                str1 = string.Concat("key_", ii.ToString());
                hash1.Add(str1, ii);
            }

            dicEnum1 = hash1.GetEnumerator();

            //Enumerator (well, Hashtable really) does not hold values in the order we put them in!!
            //so we will use 2 ques to confirm that all the keys and values we put inside the hashtable was there
            que1 = new Queue();
            que2 = new Queue();

            while (dicEnum1.MoveNext() != false)
            {
                strRetKey = (string)dicEnum1.Key;
                iExpValue = Convert.ToInt32(dicEnum1.Value);

                //we make sure that the values are there

                Assert.True(hash1.ContainsKey(strRetKey));
                Assert.True(hash1.ContainsValue(iExpValue));

                //we will make sure that enumerator get all the objects
                que1.Enqueue(strRetKey);
                que2.Enqueue(iExpValue);
            }

            //making sure the que size is right
            Assert.Equal(100, que1.Count);
            Assert.Equal(100, que2.Count);

            //[] 3) change hash table externally whilst in the middle of enumerating

            hash1 = new Hashtable();
            for (ii = 0; ii < 100; ii++)
            {
                str1 = string.Concat("key_", ii.ToString());
                hash1.Add(str1, ii);
            }

            dicEnum1 = hash1.GetEnumerator();

//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:GetEnumeratorTests.cs

示例12: RandomMinesPosition

    /// <summary>
    /// Randoms the mines position.
    /// </summary>
    /// <returns>The mines position.</returns>
    /// <param name="sum">Sum.</param>
    int[] RandomMinesPosition(int sum)
    {
        int[] arr = new int[sum];
        int j = 0;
        //表示键和值对的集合。 se hashable to store key and values
        Hashtable hashtable = new Hashtable();
        System.Random rm = new System.Random();
        for (int i = 0; hashtable.Count < sum; i++)
        {
            //返回一个小于所指定最大值的非负随机数  return a number < max but >0
            int nValue = rm.Next(numOfCubes);
            //containsValue(object value)   是否包含特定值
            if (!hashtable.ContainsValue(nValue) && nValue != 0)
            {
                //把键和值添加到hashtable add key value to hashtable
                hashtable.Add(nValue, nValue);
                //Debug.Log(i);
                arr[j] = nValue;

                j++;
            }
        }
        int temp;
        //最多做n-1趟排序  sort array
        for (int i = 0; i < arr.Length - 1; i++)
        {
            //对当前无序区间score[0......length-i-1]进行排序(j的范围很关键,这个范围是在逐步缩小的)
            for (j = 0; j < arr.Length - i - 1; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        return arr;
    }
开发者ID:haolemawo,项目名称:TiminesSweeper-3D-,代码行数:45,代码来源:gameController.cs

示例13: runTest


//.........这里部分代码省略.........
     {
         ++iCountTestcases;
         hash = new Hashtable( new Hashtable(), Single.NaN );
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_0003!  hashtable should have thrown ArgumentOutOfRangeException here" );
     }
     catch( ArgumentOutOfRangeException )
     {
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1003!  we expected ArgumentOutOfRangeException but got exception " + ex.ToString() );
     }
     try
     {
         ++iCountTestcases;
         hash = new Hashtable( new Hashtable(), 100.1f );
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_0004!  hashtable should have thrown ArgumentOutOfRangeException here" );
     }
     catch( ArgumentOutOfRangeException )
     {
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1004!  we expected ArgumentOutOfRangeException but got exception " + ex.ToString() );
     }
     try
     {
         ++iCountTestcases;
         hash = new Hashtable( new Hashtable(), 1f );
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1005!  we expected no exception but got exception " + ex.ToString() );
     }
     try
     {
         ++iCountTestcases;
         hash = new Hashtable( new Hashtable(new Hashtable(new Hashtable(new Hashtable(new Hashtable()), 1f), 1f), 1f), 1f );
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1006!  we expected no exception but got exception " + ex.ToString() );
     }
     try
     {
         ++iCountTestcases;
         Hashtable tempHash = new Hashtable();
         for ( long i = Int64.MinValue; i < Int64.MinValue + 100; i++ )
         {
             tempHash.Add( i, i );
         }
         hash = new Hashtable( tempHash, 1f );
         for ( long i = Int64.MinValue; i < Int64.MinValue + 100; i++ )
         {
             if ( ! hash.ContainsKey( i ) )
             {
                 Console.WriteLine( s_strTFAbbrev + " Error_007a!  new Hashtable does not contain KEY " + i.ToString() );
             }
             else if ( ! hash.ContainsValue( i ) )
             {
                 Console.WriteLine( s_strTFAbbrev + " Error_007b!  new Hashtable does not contain VALUE " + i.ToString() );
             }
         }
         ++iCountTestcases;
         tempHash.Clear();
         for ( long i = Int64.MinValue; i < Int64.MinValue + 100; i++ )
         {
             if ( ! hash.ContainsKey( i ) )
             {
                 Console.WriteLine( s_strTFAbbrev + " Error_007a!  new Hashtable does not contain KEY " + i.ToString() );
             }
             else if ( ! hash.ContainsValue( i ) )
             {
                 Console.WriteLine( s_strTFAbbrev + " Error_007b!  new Hashtable does not contain VALUE " + i.ToString() );
             }
         }
     }
     catch( Exception ex )
     {
         ++iCountErrors;
         Console.WriteLine(  s_strTFAbbrev +" Error_1007!  we expected no exception but got exception " + ex.ToString() );
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+ s_strTFPath +" "+ s_strTFName +"  ,iCountTestcases="+ iCountTestcases.ToString() );
         return true;
     }
     else
     {
         Console.WriteLine( "ACTIVE BUGS: " + s_strActiveBugNums );
         Console.WriteLine( "FAiL!   "+ s_strTFPath +" "+ s_strTFName +"  ,iCountErrors="+ iCountErrors.ToString() +" ,BugNums?: "+ s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co1658ctor_df.cs

示例14: TestRemove_SameHashcode

        public static void TestRemove_SameHashcode()
        {
            // We want to add and delete items (with the same hashcode) to the hashtable in such a way that the hashtable
            // does not expand but have to tread through collision bit set positions to insert the new elements. We do this
            // by creating a default hashtable of size 11 (with the default load factor of 0.72), this should mean that
            // the hashtable does not expand as long as we have at most 7 elements at any given time?

            var hash = new Hashtable();
            var arrList = new ArrayList();
            for (int i = 0; i < 7; i++)
            {
                var hashConfuse = new BadHashCode(i);
                arrList.Add(hashConfuse);
                hash.Add(hashConfuse, i);
            }

            var rand = new Random(-55);

            int iCount = 7;
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    Assert.Equal(hash[arrList[j]], ((BadHashCode)arrList[j]).Value);
                }

                // Delete 3 elements from the hashtable
                for (int j = 0; j < 3; j++)
                {
                    int iElement = rand.Next(6);
                    hash.Remove(arrList[iElement]);
                    Assert.False(hash.ContainsValue(null));
                    arrList.RemoveAt(iElement);

                    int testInt = iCount++;
                    var hashConfuse = new BadHashCode(testInt);
                    arrList.Add(hashConfuse);
                    hash.Add(hashConfuse, testInt);
                }
            }
        }
开发者ID:benpye,项目名称:corefx,代码行数:41,代码来源:HashtableTests.cs

示例15: runTest


//.........这里部分代码省略.........
                 serValues = (Object[])ser1.GetValue("Values", typeof(Object[]));
                     Array.Sort(serKeys);
             Array.Sort(serValues);
             for(int i=0; i<iNumberOfItems; i++)
             {
                 if((Int32)serKeys[i] != i) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_1nd342_" + i + "! Expected value not returned, " + i);
                 }
                 if(!((String)serValues[i]).Equals("String_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_7539fdg_" + i + "! Expected value not returned, " + i);
                 }
             }
             try
             {
                 iCountTestcases++;
                 dic1.GetObjectData(null, new StreamingContext());
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
             }
             catch(ArgumentNullException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_6572fdg! Unexpected exception thrown, " + ex);
             }
             iCountTestcases++;
             hsh1 = new Hashtable();
             for(int i=0; i<10; i++)
             {
                 hsh1.Add("Key_" + i, "Value_" + i);
             }
             BinaryFormatter formatter = new BinaryFormatter();
             ms1 = new MemoryStream();
             formatter.Serialize(ms1, hsh1);
             ms1.Position = 0;
             hsh4 = (Hashtable)formatter.Deserialize(ms1);
             if(hsh4.Count != hsh1.Count) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_072xsf! Expected value not returned, " + hsh4.Count);
             }				
             strValueArr = new DictionaryEntry[hsh4.Count];
             hsh4.CopyTo(strValueArr, 0);
             hsh3 = new Hashtable();
             for(int i=0; i<10; i++)
             {
                 if(!hsh4.Contains("Key_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_742ds8f! Expected value not returned, " + hsh4.Contains("Key_" + i));
                 }				
                 if(!hsh4.ContainsKey("Key_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_742389dsaf! Expected value not returned, " + hsh4.ContainsKey("Key_" + i));
                 }				
                 if(!hsh4.ContainsValue("Value_" + i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_0672esfs! Expected value not returned, " + hsh4.ContainsValue("Value_" + i));
                 }				
                 if(!hsh1.ContainsValue(((DictionaryEntry)strValueArr[i]).Value)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_87429dsfd! Expected value not returned, " + ((DictionaryEntry)strValueArr[i]).Value);
                 }				
                 try
                 {
                     hsh3.Add(((DictionaryEntry)strValueArr[i]).Value, null);
                 }
                 catch(Exception)
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_74298dsd! Exception thrown for  " + ((DictionaryEntry)strValueArr[i]).Value);
                 }
             }
         } while (false);
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co3949getobjectdata_sersc.cs


注:本文中的Hashtable.ContainsValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。