本文整理汇总了C#中System.Collections.Dictionary.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.CopyTo方法的具体用法?C# Dictionary.CopyTo怎么用?C# Dictionary.CopyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.CopyTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyTo
public void CopyTo()
{
IDictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("Key", "Value");
dict.Add("OtherKey", "OtherValue");
dict = dict.ToReadOnlyDictionary();
var values = new KeyValuePair<string, string>[3];
var expectedValues = new[]
{
KeyValuePair.Create("Key", "Value"),
KeyValuePair.Create("OtherKey", "OtherValue"),
default(KeyValuePair<string, string>)
};
dict.CopyTo(values, 0);
Assert.IsTrue(values.SequenceEqual(expectedValues));
dict.CopyTo(values, 1);
expectedValues[2] = expectedValues[1];
expectedValues[1] = expectedValues[0];
Assert.IsTrue(values.SequenceEqual(expectedValues));
}
示例2: SortDictionaryKeys
internal static List<int> SortDictionaryKeys(Dictionary<int, string>.KeyCollection keys)
{
int[] tmp = new int[keys.Count];
keys.CopyTo(tmp, 0);
List<int> ret = new List<int>(tmp);
ret.Sort();
return ret;
}
示例3: readUIDigitals
private Dictionary<string, bool> readUIDigitals(Dictionary<string, bool>.KeyCollection keys)
{
Dictionary<string, bool> digitals = new Dictionary<string,bool>();
string[] keyArray = new string[keys.Count];
keys.CopyTo(keyArray, 0);
for (int i = 0; i < keys.Count; i++)
{
digitals[keyArray[i]] = controlWindow.ReadDigital(keyArray[i]);
}
return digitals;
}
示例4: GenericDictionarySource
public void GenericDictionarySource()
{
var source = new Dictionary<string, object>();
// guid
var guidValue = new Guid("21EC2020-3AEA-1069-A2DD-08002B30309D");
source["GuidPty"] = guidValue;
Assert.AreEqual(guidValue, source.CopyTo<TargetType>().GuidPty);
source["GuidPty"] = guidValue.ToString();
Assert.AreEqual(guidValue, source.CopyTo<TargetType>().GuidPty);
source["GuidPty"] = guidValue.ToByteArray();
Assert.AreEqual(guidValue, source.CopyTo<TargetType>().GuidPty);
// int
source["IntPty"] = 345;
Assert.AreEqual(345, source.CopyTo<TargetType>().IntPty);
source["IntPty"] = 345.ToString(CultureInfo.InvariantCulture);
Assert.AreEqual(345, source.CopyTo<TargetType>().IntPty);
source["IntPty"] = (long)345;
Assert.AreEqual(345, source.CopyTo<TargetType>().IntPty);
source["IntPty"] = int.MaxValue;
Assert.AreEqual(int.MaxValue, source.CopyTo<TargetType>().IntPty);
// enum pty
source["EnumPty"] = TargetType.TestEnum.Three;
Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);
source["EnumPty"] = TargetType.TestEnum.Three.ToString();
Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);
source["EnumPty"] = (int)TargetType.TestEnum.Three;
Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);
source["EnumPty"] = (byte)TargetType.TestEnum.Three;
Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);
source["EnumPty"] = (long)TargetType.TestEnum.Three;
Assert.AreEqual(TargetType.TestEnum.Three, source.CopyTo<TargetType>().EnumPty);
// obj pty
var obj = new object();
source["ObjPty"] = obj;
Assert.AreEqual(obj, source.CopyTo<TargetType>().ObjPty);
}
示例5: readUIAnalogs
private Dictionary<string, double> readUIAnalogs(Dictionary<string, double>.KeyCollection keys)
{
Dictionary<string, double> analogs = new Dictionary<string, double>();
string[] keyArray = new string[keys.Count];
keys.CopyTo(keyArray, 0);
for (int i = 0; i < keys.Count; i++)
{
analogs[keyArray[i]] = controlWindow.ReadAnalog(keyArray[i]);
}
return analogs;
}