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


C# SortedList.TrimToSize方法代码示例

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


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

示例1: runTest

 public virtual bool runTest()
 {
     Console.Error.WriteLine( "Co4345TrimToSize  runTest() started." );
     String strLoc="Loc_000oo";
     StringBuilder sblMsg = new StringBuilder( 99 );
     int iCountErrors = 0;
     int iCountTestcases = 0;
     SortedList sl2 = null;
     StringBuilder sbl3 = new StringBuilder( 99 );
     StringBuilder sbl4 = new StringBuilder( 99 );
     StringBuilder sblWork1 = new StringBuilder( 99 );
     String str5 = null;
     String str6 = null;
     String str7 = null;
     String s1 = null;
     String s2 = null;
     String s3 = null;
     int[] in4a = new int[9];
     int nCapacity = 100;
     bool bol = false;
     int i = 0;
     try
     {
     LABEL_860_GENERAL:
         do
         {
             strLoc="100cc";
             iCountTestcases++;
             sl2 = new SortedList( this );
             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;
             }
             if (s3 != null) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_101bc! " );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc="Loc_141aa";
             for (i=0; i<32; i++) 
             {
                 ++iCountTestcases;
                 sblMsg.Length =  0 ;
                 sblMsg.Append("key_");
                 sblMsg.Append(i);
                 s1 = sblMsg.ToString();
                 sblMsg.Length =  0 ;
                 sblMsg.Append("val_");
                 sblMsg.Append(i);
                 s2 = sblMsg.ToString();
                 sl2.Add (s1, s2);
             }
             ++iCountTestcases;
             sl2.Add ("key_32", "val_32");
             ++iCountTestcases;
             if (sl2.Count  != 33) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_gh40! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             for (i=0; i < 10; i++) 
             {
                 ++iCountTestcases;
                 sl2.Remove ("key_" + i.ToString()); 
             }
             strLoc="Loc_141aa";
             ++iCountTestcases;
             if (sl2.Count  != 23) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_gh45! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             ++iCountTestcases;
             sl2.TrimToSize ();
             ++iCountTestcases;
             sl2.Clear();
             ++iCountTestcases;
             sl2.TrimToSize ();
         } while ( false );
     }
     catch( Exception exc_general )
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co4345trimtosize.cs

示例2: TestTrimToSizeBasic

        public void TestTrimToSizeBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);
            //

            SortedList sl2 = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            String s1 = null;
            String s2 = null;
            String s3 = null;

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

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

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

            //   Testcase: add few key-val pairs

            // start adding elements
            for (i = 0; i < 32; i++)
            {
                sblMsg.Length = 0;
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();

                sblMsg.Length = 0;
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                sl2.Add(s1, s2);
            }

            //
            //  add one more elemnt now the capacity should be doubled
            //
            sl2.Add("key_32", "val_32");
            Assert.Equal(33, sl2.Count);

            //
            //   Testcase: now Remove few elements and TrimToSize
            //
            for (i = 0; i < 10; i++)
            {
                sl2.Remove("key_" + i.ToString()); // remove the current object
            }

            //   Testcase:  validate the Count and capacity
            Assert.Equal(23, sl2.Count);

            //  now TrimToSize
            sl2.TrimToSize();

            //  clear the list
            sl2.Clear();

            //  now TrimToSize
            sl2.TrimToSize();
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:72,代码来源:TrimToSizeTests.cs

示例3: SortListBox

    //------------------------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------------------------
    private void SortListBox(ref ListBox pList)
    {
        SortedList lListItems = new SortedList();

            if (pList.Items.Count <= 1)
                return;

            //add DropDownList items to SortedList
            foreach (ListItem lItem in pList.Items)
            {
                lListItems.Add(lItem.Text, lItem);
            }

            lListItems.TrimToSize();

            //clear DropDownList
            pList.Items.Clear();
            //add sorted items to listbox
            for (int i = 0; i < lListItems.Count; i++)
                pList.Items.Add((ListItem)lListItems[lListItems.GetKey(i)]);
    }
开发者ID:ssommerfeldt,项目名称:TAC_AH,代码行数:23,代码来源:SpeEmailForm.ascx.cs


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