本文整理汇总了C#中SortedList.GetKeyList方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.GetKeyList方法的具体用法?C# SortedList.GetKeyList怎么用?C# SortedList.GetKeyList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList.GetKeyList方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
示例2: TestGetKeyListBasic
public void TestGetKeyListBasic()
{
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(); //using default IComparable implementation from Integer4
// which is used here as key-val elements.
// 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));
}
// testcase: GetKeyList
// first test the boundaries on the Remove method thru GetEnumerator implementation
en = (IEnumerator)sl2.GetKeyList().GetEnumerator();
// Boundary for Current
Assert.Throws<InvalidOperationException>(() =>
{
Object objThrowAway = en.Current;
}
);
j = 100;
// go over the enumarator
en = (IEnumerator)sl2.GetKeyList().GetEnumerator();
while (en.MoveNext())
{
// Current to see the order
i3 = (int)en.Current;
Assert.Equal(i3, j);
// Current again to see the same order
i3 = (int)en.Current;
Assert.Equal(i3, j);
j++;
}
// Boundary for Current
Assert.Throws<InvalidOperationException>(() =>
{
Object objThrowAway = en.Current;
}
);
// Boundary for MoveNext: call MoveNext to make sure it returns false
Assert.False((en.MoveNext()) || (j != 200));
//.........这里部分代码省略.........
示例3: TestGetValueListBasic
//.........这里部分代码省略.........
//
// 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);
// now modify the sortedlist while enumerator is still active
en = (IEnumerator)sl2.GetKeyList().GetEnumerator(); //can remove an item thru en
en.MoveNext();
sl2[1] = 0; // Set (int index, object val) // this works fine
// Boundary for MoveNext
Assert.Throws<InvalidOperationException>(() =>
{
en.MoveNext();
});
}
示例4: runTest
public virtual bool runTest()
{
Console.Error.WriteLine( "Co4339GetKeyList 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 ex )
{
++iCountErrors;
Console.WriteLine( "Err_001dt, ArgumentNullException expected but got " + ex.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 (ArgumentException)
{
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_34fj! - must not 've thrown ArgExc" );
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 ;
//.........这里部分代码省略.........
示例5: 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();
//.........这里部分代码省略.........