本文整理汇总了C#中ListDictionary.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ListDictionary.CopyTo方法的具体用法?C# ListDictionary.CopyTo怎么用?C# ListDictionary.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListDictionary
的用法示例。
在下文中一共展示了ListDictionary.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToTest
public static void CopyToTest(ListDictionary ld, KeyValuePair<string, string>[] data)
{
DictionaryEntry[] translated = data.Select(kv => new DictionaryEntry(kv.Key, kv.Value)).ToArray();
DictionaryEntry[] full = new DictionaryEntry[data.Length];
ld.CopyTo(full, 0);
Assert.Equal(translated, full);
DictionaryEntry[] large = new DictionaryEntry[data.Length * 2];
ld.CopyTo(large, data.Length / 2);
for (int i = 0; i < large.Length; i++)
{
if (i < data.Length / 2 || i >= data.Length + data.Length / 2)
{
Assert.Equal(new DictionaryEntry(), large[i]);
Assert.Null(large[i].Key);
Assert.Null(large[i].Value);
}
else
{
Assert.Equal(translated[i - data.Length / 2], large[i]);
}
}
}
示例2: CopyTo_ArgumentInvalidTest
public static void CopyTo_ArgumentInvalidTest(ListDictionary ld, KeyValuePair<string, string>[] data)
{
Assert.Throws<ArgumentNullException>("array", () => ld.CopyTo(null, 0));
Assert.Throws<ArgumentOutOfRangeException>("index", () => ld.CopyTo(data, -1));
if (data.Length > 0)
{
Assert.Throws<ArgumentException>(() => ld.CopyTo(new KeyValuePair<string, string>[1, data.Length], 0));
Assert.Throws<ArgumentException>(() => ld.CopyTo(new KeyValuePair<string, string>[0], data.Length - 1));
Assert.Throws<ArgumentException>(() => ld.CopyTo(new KeyValuePair<string, string>[data.Length - 1], 0));
Assert.Throws<InvalidCastException>(() => ld.CopyTo(new int[data.Length], 0));
}
}
示例3: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
ListDictionary ld;
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"
};
Array destination;
int cnt = 0;
try
{
intl = new IntlStrings();
Console.WriteLine("--- create dictionary ---");
strLoc = "Loc_001oo";
iCountTestcases++;
ld = new ListDictionary();
Console.WriteLine("1. Copy empty dictionary into empty array");
iCountTestcases++;
destination = Array.CreateInstance(typeof(Object), 0);
Console.WriteLine(" destination Length = " + destination.Length);
Console.WriteLine(" - CopyTo(arr, -1)");
try
{
ld.CopyTo(destination, -1);
iCountErrors++;
Console.WriteLine("Err_0001a, no exception");
}
catch (ArgumentOutOfRangeException ex)
{
Console.WriteLine(" Expected exception: {0}", ex.Message);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_001b, unexpected exception: {0}", e.ToString());
}
iCountTestcases++;
Console.WriteLine(" - CopyTo(arr, 0)");
try
{
ld.CopyTo(destination, 0);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_001c, unexpected exception: {0}", e.ToString());
}
iCountTestcases++;
Console.WriteLine(" - CopyTo(arr, 1)");
try
{
ld.CopyTo(destination, 1);
}
catch (Exception e)
{
iCountErrors++;
Console.WriteLine("Err_001d, unexpected exception: {0}", e.ToString());
}
Console.WriteLine("2. Copy empty dictionary into non-empty array");
iCountTestcases++;
destination = Array.CreateInstance(typeof(Object), values.Length);
for (int i = 0; i < values.Length; i++)
{
destination.SetValue(values[i], i);
}
ld.CopyTo(destination, 0);
if( destination.Length != values.Length)
{
iCountErrors++;
Console.WriteLine("Err_0002a, altered array after copying empty dictionary");
}
//.........这里部分代码省略.........