本文整理汇总了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
}
示例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 ();
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
}
}