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


C# SortedList.TrimToSize方法代码示例

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


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

示例1: TestTrimToSize

		public void TestTrimToSize ()
		{
			SortedList sl1 = new SortedList (24);

			sl1.TrimToSize ();
#if !NET_2_0 // no such expectation as it is broken in .NET 2.0
			Assert.AreEqual (icap, sl1.Capacity, "#1");
#endif

			for (int i = 72; i >= 0; i--)
				sl1.Add (100 + i, i);
			sl1.TrimToSize ();
#if !NET_2_0 // no such expectation as it is broken in .NET 2.0
			Assert.AreEqual (73, sl1.Capacity, "#2");
#endif
		}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:SortedListTest.cs

示例2: TestTrimToSize

		public void TestTrimToSize ()
		{
			SortedList sl1 = new SortedList (24);

			sl1.TrimToSize ();

			for (int i = 72; i >= 0; i--)
				sl1.Add (100 + i, i);
			sl1.TrimToSize ();
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:10,代码来源:SortedListTest.cs

示例3: SplitString

 /// <summary>
 /// Splits a string into words and returns a sorted list that contains the
 /// words and the number of times they appear in the original string.
 /// </summary>
 /// <param name="strInput">The string to split into words</param>
 /// <returns>A SortedList containing the words and their frequency</returns>
 private SortedList SplitString(string strInput)
 {
     SortedList sl=new SortedList();
     string[] words=strInput.Split(Delimiters);
     foreach(string s in words)
     {
         string word=s.Trim();
         if(word.Length>1)
         {
             if((ExistsInAllStopWords(word))||(IsNumericString(word)))
             {
                 continue;
             }
             try
             {
                 word=StemWord(word);
                 if(sl.ContainsKey(word))
                 {
                     //this word already exists. Just increment it's count
                     sl[word]=(int)sl[word]+1;
                 }
                 else
                 {
                     //The word does not exist, add it to the list with a count of 1
                     sl.Add(word, 1);
                 }
             }
             catch
             {
                 continue;
             }
         }
     }
     sl.TrimToSize();
     return sl;
 }
开发者ID:modernist,项目名称:CrawlWave,代码行数:42,代码来源:WordExtractor.cs

示例4: TestTrimToSize

	public void TestTrimToSize() {
		SortedList sl1 = new SortedList(24);
		
		sl1.TrimToSize();
		AssertEquals("sl.TrimToSize: incorrect capacity after trimming empty list",icap,sl1.Capacity);
		
		for (int i = 72; i>=0; i--) sl1.Add(100+i,i);
		sl1.TrimToSize();
		AssertEquals("sl.TrimToSize: incorrect capacity after trimming a list",73,sl1.Capacity);
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:10,代码来源:SortedListTest.cs

示例5: 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:johnhhm,项目名称:corefx,代码行数:72,代码来源:TrimToSizeTests.cs

示例6: PopulateAssetListControl

 /// <summary>
 /// Populates the asset list control.
 /// </summary>
 /// <param name="listControl">The list control.</param>
 /// <param name="arrText">The arr text.</param>
 /// <param name="arrValue">The arr value.</param>
 public void PopulateAssetListControl(ListControl listControl, string[] arrText, string[] arrValue)
 {
     if(listControl != null && arrText != null)
     {
         SortedList sortedAssetNames = new SortedList();
         for(int intIndex = 0; intIndex < arrText.Length; intIndex++)
         {
             sortedAssetNames.Add(arrValue[intIndex], arrText[intIndex]);
         }
         sortedAssetNames.TrimToSize();
         listControl.DataSource = sortedAssetNames;
         listControl.DataValueField = "key";
         listControl.DataTextField = "value";
         listControl.DataBind();
     }
 }
开发者ID:vijaymca,项目名称:Dotnet,代码行数:22,代码来源:CommonUtility.cs

示例7: LoadSearcheNames

 /// <summary>
 /// Loads the searche names.
 /// </summary>
 /// <param name="asset">The asset.</param>
 /// <param name="dropdownLstBx">The dropdown LST bx.</param>
 public void LoadSearcheNames(string asset, DropDownList dropdownLstBx)
 {
     const string SEARCHES = "Searches";
     const string SPLITSTRING = ";#";
     const string VALUE = "Value";
     const string SEARCHNAMEEXP = "%SEARCHNAME%";
     string strCmlQryAsstSrchMap = "<Where><Eq><FieldRef Name=\"Asset\" /><Value Type=\"Lookup\">" + asset + "</Value></Eq></Where>";
     string strViewFields = @"<FieldRef Name='Title'/><FieldRef Name='" + SEARCHES + "'/>";
     string strCmlQrySrchNames = "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + SEARCHNAMEEXP + "</Value></Eq></Where>";
     string strSearcheNames = string.Empty;
     string strSrchName = string.Empty;
     string strSrchValue = string.Empty;
     DataTable objDataTable = null;
     SortedList sortedLstSrchNames = new SortedList();
     try
     {
         objDataTable = ((MOSSServiceManager)objMossController).ReadList(SPContext.Current.Site.Url, ASSETSEARCHMAPPINGLIST, strCmlQryAsstSrchMap, strViewFields);
         if(objDataTable != null && objDataTable.Rows.Count > 0 && objDataTable.Rows[0][SEARCHES] != null)
         {
             strSearcheNames = (string)objDataTable.Rows[0][SEARCHES];
         }
         if(!string.IsNullOrEmpty(strSearcheNames))
         {
             string[] arrSearches = strSearcheNames.Split(SPLITSTRING.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             for(int intSrchNamesCounter = 0; intSrchNamesCounter < arrSearches.Length; intSrchNamesCounter += 2)
             {
                 if(!string.IsNullOrEmpty(arrSearches[intSrchNamesCounter]))
                 {
                     strSrchName = arrSearches[intSrchNamesCounter];
                     strSrchValue = GetColValueFromDtRow(GetLookUpColumnRow(SEARCHES, strCmlQrySrchNames.Replace(SEARCHNAMEEXP,arrSearches[intSrchNamesCounter])), VALUE);
                     sortedLstSrchNames.Add(strSrchValue, strSrchName);
                 }
             }
         }
         sortedLstSrchNames.TrimToSize();
         dropdownLstBx.DataSource = sortedLstSrchNames;
         dropdownLstBx.DataTextField = "value";
         dropdownLstBx.DataValueField = "key";
         dropdownLstBx.DataBind();
         dropdownLstBx.Items.Insert(0, "---Select---");
     }
     finally
     {
         if(objDataTable != null)
         {
             objDataTable.Dispose();
         }
     }
 }
开发者ID:vijaymca,项目名称:Dotnet,代码行数:54,代码来源:RolesProfilesHelper.cs


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