本文整理汇总了C#中StringDictionary.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# StringDictionary.GetEnumerator方法的具体用法?C# StringDictionary.GetEnumerator怎么用?C# StringDictionary.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringDictionary
的用法示例。
在下文中一共展示了StringDictionary.GetEnumerator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runTest
//.........这里部分代码省略.........
if( destination.Length != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, altered array after copying empty collection");
}
if (destination.Length == values.Length)
{
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (String.Compare(destination.GetValue(i).ToString(), values[i], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, altered item {0} after copying empty collection", i);
}
}
}
Console.WriteLine("3. add simple strings and CopyTo(Array, 0)");
strLoc = "Loc_003oo";
iCountTestcases++;
cnt = sd.Count;
int len = values.Length;
for (int i = 0; i < len; i++)
{
sd.Add(keys[i], values[i]);
}
if (sd.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0003a, count is {0} instead of {1}", sd.Count, values.Length);
}
destination = Array.CreateInstance(typeof(Object), len);
sd.CopyTo(destination, 0);
IEnumerator en = sd.GetEnumerator();
for (int i = 0; i < len; i++)
{
en.MoveNext();
DictionaryEntry curr = (DictionaryEntry)en.Current;
iCountTestcases++;
if ( String.Compare(curr.Value.ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}b, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value, curr.Value);
}
iCountTestcases++;
if ( String.Compare(curr.Key.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0003_{0}c, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key, curr.Key);
}
}
Console.WriteLine("4. add simple strings and CopyTo(Array, {0})", values.Length);
sd.Clear();
strLoc = "Loc_004oo";
iCountTestcases++;
for (int i = 0; i < len; i++)
{
sd.Add(keys[i], values[i]);
}
if (sd.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0004a, count is {0} instead of {1}", sd.Count, values.Length);
}
destination = Array.CreateInstance(typeof(Object), len*2);
sd.CopyTo(destination, len);
示例2: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
StringDictionary sd;
IEnumerator en;
DictionaryEntry curr;
string [] values =
{
"a",
"aa",
"",
" ",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"one",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
try
{
Console.WriteLine("--- create dictionary ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sd = new StringDictionary();
Console.WriteLine("1. Enumerator for empty dictionary");
Console.WriteLine(" - get type");
iCountTestcases++;
en = sd.GetEnumerator();
string type = en.GetType().ToString();
if ( type.IndexOf("Enumerator", 0) == 0 )
{
iCountErrors++;
Console.WriteLine("Err_0001a, type is not Enumerator");
}
Console.WriteLine(" - MoveNext");
iCountTestcases++;
bool res = en.MoveNext();
if ( res )
{
iCountErrors++;
Console.WriteLine("Err_0001b, MoveNext returned true");
}
Console.WriteLine(" - Current");
iCountTestcases++;
try
{
curr = (DictionaryEntry)en.Current;
iCountErrors++;
Console.WriteLine("Err_0001c, no exception");
}
catch (InvalidOperationException ex)
{
Console.WriteLine(" expected exception: " + ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString());
}
Console.WriteLine("2. GetEnumerator for filled collection");
strLoc = "Loc_002oo";
iCountTestcases++;
for (int i = 0; i < values.Length; i++)
{
sd.Add(keys[i], values[i]);
}
Console.WriteLine(" - get type");
iCountTestcases++;
en = sd.GetEnumerator();
type = en.GetType().ToString();
if ( type.IndexOf("Enumerator", 0) == 0 )
{
iCountErrors++;
Console.WriteLine("Err_0002a, type is not Enumerator");
}
Console.WriteLine(" - MoveNext and Current within collection");
for (int i = 0; i < sd.Count; i++)
{
iCountTestcases++;
res = en.MoveNext();
if ( !res )
//.........这里部分代码省略.........