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


C# SortedList.GetValueList方法代码示例

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


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

示例1: TestGetKeyValueList

        public void TestGetKeyValueList()
        {
            var dic1 = new SortedList();

            for (int i = 0; i < 100; i++)
                dic1.Add("Key_" + i, "Value_" + i);

            var ilst1 = dic1.GetKeyList();
            var hsh1 = new Hashtable();

            DoIListTests(dic1, ilst1, hsh1, DicType.Key);

            Assert.False(hsh1.Count != 2
                || !hsh1.ContainsKey("IsReadOnly")
                || !hsh1.ContainsKey("IsFixedSize"), "Error, KeyList");


            dic1 = new SortedList();
            for (int i = 0; i < 100; i++)
                dic1.Add("Key_" + i, "Value_" + i);

            ilst1 = dic1.GetValueList();
            hsh1 = new Hashtable();
            DoIListTests(dic1, ilst1, hsh1, DicType.Value);

            Assert.False(hsh1.Count != 2
                || !hsh1.ContainsKey("IsReadOnly")
                || !hsh1.ContainsKey("IsFixedSize"), "Error, ValueList");
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:29,代码来源:WrapperTests.cs

示例2: runTest

 public virtual bool runTest()
 {
     Console.Error.WriteLine( "Co3718GetValueList  runTest() started." );
     String strLoc="Loc_000oo";
     StringBuilder sblMsg = new StringBuilder( 99 );
     int iCountErrors = 0;
     int iCountTestcases = 0;
     SortedList sl2 = null;
     IEnumerator en = null;
     StringBuilder sbl3 = new StringBuilder( 99 );
     StringBuilder sbl4 = new StringBuilder( 99 );
     StringBuilder sblWork1 = new StringBuilder( 99 );
     int i3 = 0;
     int[] in4a = new int[9];
     int i = 0;
     int j = 0;
     try
     {
         do
         {
             strLoc="100cc";
             iCountTestcases++;
             sl2 = new SortedList();
             iCountTestcases++;
             if ( sl2 == null )
             {
                 Console.WriteLine( strTest+ "E_101" );
                 Console.WriteLine( strTest+ "SortedList creation failure" );
                 ++iCountErrors;
                 break;
             }
             iCountTestcases++;
             if ( sl2.Count  != 0 )
             {
                 Console.WriteLine( strTest+ "E_102" );
                 Console.WriteLine( strTest+ "New SortedList is not empty" );
                 ++iCountErrors;
             }
             strLoc="Loc_100aa";
             ++iCountTestcases;
             try 
             {
                 sl2[null] = 0;
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_2764! - must 've thrown ArgExc" );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             catch (ArgumentNullException) {}
             catch (Exception exgen )
             {
                 ++iCountErrors;
                 Console.WriteLine( "Err_0001dt,  Expected Exception ArgumentNullException but thrown " + exgen.ToString() );
             }
             ++iCountTestcases;
             if (sl2.Count  != 0) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_48ff! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc="Loc_110aa";
             ++iCountTestcases;
             try 
             {
                 sl2[(Object)100] = (Object)null;
             }
             catch (Exception exgen) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_34fj! - must not 've thrown " + exgen.ToString() );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             ++iCountTestcases;
             if (sl2.Count != 1) 
             { 
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_60ff! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc="Loc_120aa";
             ++iCountTestcases;
             try 
             {
                 sl2[(Object)100] = 1; 
             }
             catch (Exception exc) 
             {
                 ++iCountErrors;
                 Console.Error.WriteLine ( "POINTTOBREAK: Error Err_49ff! - " + exc.ToString());
             }
             if (sl2.Count != 1) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co3718getvaluelist.cs

示例3: TestGetValueListBasic

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

            SortedList sl2 = null;
            IEnumerator en = null;
            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            int i3 = 0;
            int i = 0;
            int j = 0;
            //
            // Constructor: Create SortedList using this as IComparer and default settings.
            //
            sl2 = new SortedList();

            // Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            // Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);

            // Testcase: Set - null key, ArgExc expected
            Assert.Throws<ArgumentNullException>(() =>
                {
                    sl2[null] = 0;
                });

            Assert.Equal(0, sl2.Count);

            // Testcase: Set - null val
            sl2[(object)100] = (object)null;
            Assert.Equal(1, sl2.Count);

            // Testcase: vanila Set
            sl2[(object)100] = 1;
            Assert.Equal(1, sl2.Count);
            sl2.Clear();
            Assert.Equal(0, sl2.Count);

            // Testcase: add key-val pairs
            for (i = 0; i < 100; i++)
            {
                sl2.Add(i + 100, i);
            }
            Assert.Equal(100, sl2.Count);

            for (i = 0; i < 100; i++)
            {
                j = i + 100;
                Assert.True(sl2.ContainsKey((int)j));
                Assert.True(sl2.ContainsValue(i));

                object o2 = sl2[(int)j];

                Assert.NotNull(o2);
                Assert.True(o2.Equals(i), "Error, entry for key " + j.ToString() + " is " + o2.ToString() + " but should have been " + i.ToString());
            } // FOR

            //  testcase: GetValueList
            // ICollection.GetEnumerator() first test the boundaries on the Remove method thru GetEnumerator implementation
            en = (IEnumerator)sl2.GetValueList().GetEnumerator();

            // Boundary for Current
            Assert.Throws<InvalidOperationException>(() =>
                    {
                        object throwaway = en.Current;
                    }
            );

            j = 0;
            // go over the enumarator
            en = (IEnumerator)sl2.GetValueList().GetEnumerator();
            while (en.MoveNext())
            {
                // Current to see the order
                i3 = (int)en.Current;
                Assert.Equal(i3, j);

                // GetObject again to see the same order
                i3 = (int)en.Current;
                Assert.Equal(i3, j);

                j++;
            }

            // Boundary for GetObject
            Assert.Throws<InvalidOperationException>(() =>
                    {
                        object throwawayobj = en.Current;
                    }
            );

            // Boundary for MoveNext: call MoveNext to make sure it returns false
            Assert.False((en.MoveNext()) || (j != 100));
            // call again MoveNext to make sure it still returns false
            Assert.False(en.MoveNext());
            Assert.Equal(100, sl2.Count);
//.........这里部分代码省略.........
开发者ID:noahfalk,项目名称:corefx,代码行数:101,代码来源:GetValueListTests.cs

示例4: runTest

 private Boolean runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = null;
     SortedList dic1;
     SortedList dic2;
     SortedList dic3;
     String[] strValueArr = null;
     DictionaryEntry[] dicEnt1 = null;
     String[] strKeyArr = null;
     ICollection icol1;
     Hashtable hsh1;
     IDictionaryEnumerator idic;
     IDictionaryEnumerator idicTest;
     IDictionaryEnumerator idicTest1;
     DictionaryEntry dicEnt;
     Hashtable hsh2;
     Hashtable hsh3;
     Hashtable hsh4;
     Object oValue;
     Int32 iNumberOfElements;
     MemoryStream ms1;
     BinaryFormatter formatter;
     IList ilst1;
     try
     {
         hsh1 = new Hashtable();
         strLoc = "Loc_04872dsf";
         iCountTestcases++;
         dic1 = new SortedList();
         icol1 = dic1.Keys;
         for(int i=0; i<100; i++)
             dic1.Add("Key_" + i, "Value_" + i);
         DoICollectionTests(dic1, icol1, hsh1, DicType.Key);
         if(hsh1.Count>0)
         {
             iCountErrors++;
             Console.WriteLine("Err_75629ewf! Keys");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_97234dsf";
         iCountTestcases++;
         dic1 = new SortedList();
         for(int i=0; i<100; i++)
             dic1.Add("Key_" + i, "Value_" + i);
         icol1 = dic1.Values;
         hsh1 = new Hashtable();
         DoICollectionTests(dic1, icol1, hsh1, DicType.Value);
         if(hsh1.Count>0)
         {
             iCountErrors++;
             Console.WriteLine("Err_94752dsg! Values");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         strLoc = "Loc_74fsgf";
         dic1 = new SortedList();
         iCountTestcases++;
         for(int i=0; i<100; i++)
             dic1.Add("Key_" + i, "Value_" + i);
         ilst1 = dic1.GetKeyList();
         hsh1 = new Hashtable();
         DoIListTests(dic1, ilst1, hsh1, DicType.Key);
         if(hsh1.Count!= 2
             || !hsh1.ContainsKey("IsReadOnly")
             || !hsh1.ContainsKey("IsFixedSize")
             )
         {
             iCountErrors++;
             Console.WriteLine("Err_7352dsafsaf! KeyList");
             idic = hsh1.GetEnumerator();
             while(idic.MoveNext())
             {
                 Console.WriteLine("<<" + idic.Key + " <<" + idic.Value + ">>");
             }
         }
         dic1 = new SortedList();
         strLoc = "Loc_97653tdsfg";
         for(int i=0; i<100; i++)
             dic1.Add("Key_" + i, "Value_" + i);
         ilst1 = dic1.GetValueList();
         hsh1 = new Hashtable();
         DoIListTests(dic1, ilst1, hsh1, DicType.Value);
         if(hsh1.Count!=2
             || !hsh1.ContainsKey("IsReadOnly")				
             || !hsh1.ContainsKey("IsFixedSize")
             )
         {
             iCountErrors++;
             Console.WriteLine("Err_3572sfn! ValueList");
             idic = hsh1.GetEnumerator();
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co3977wrappertests.cs


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