本文整理汇总了C#中KeyValuePair.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValuePair.ToDictionary方法的具体用法?C# KeyValuePair.ToDictionary怎么用?C# KeyValuePair.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValuePair
的用法示例。
在下文中一共展示了KeyValuePair.ToDictionary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AllMetrics_SampleData_Recorded
public void AllMetrics_SampleData_Recorded()
{
const int NumberOfItems = 42;
var errors = new KeyValuePair<string, Exception>[]
{
new KeyValuePair<string, Exception>("1", new Exception()),
new KeyValuePair<string, Exception>("2", new ArgumentException()),
new KeyValuePair<string, Exception>("3", new KeyNotFoundException())
};
var statistics = new InMemoryTransferStatistics(ErrorDetailsProviderMock.Instance);
statistics.Start();
for (var index = 0; index < NumberOfItems; ++index)
statistics.AddTransferred();
foreach (var error in errors)
statistics.AddError(error.Key, error.Value);
statistics.Stop();
var result = statistics.GetSnapshot();
Assert.IsNotNull(result, TestResources.NullStatisticsSnapshot);
Assert.AreNotEqual(TimeSpan.Zero, result.ElapsedTime, TestResources.StatisticsElapsedTimeIsEmpty);
Assert.AreEqual(NumberOfItems, result.Transferred, TestResources.StatisticsInvalidTransferredCount);
Assert.AreEqual(errors.Length, result.Failed, TestResources.StatisticsInvalidFailedCount);
CollectionAssert.AreEquivalent(errors.ToDictionary(e => e.Key, e => ErrorDetailsProviderMock.Instance.Get(e.Value)), result.GetErrors().ToArray(),
TestResources.StatisticsInvalidErrors);
}
示例2: AssertIndexes
private void AssertIndexes(KeyValuePair<int, string>[] data, int[] indexes)
{
var dic = data.ToDictionary(k => k.Key);
Assert.AreEqual(indexes.Length, data.Length, "Found wrong amount");
for (int i = 0; i < data.Length; ++i)
{
Assert.AreEqual(indexes[i], dic[indexes[i]].Key, "Wrong index found at position " + i);
}
}
示例3: ToDictionary
public IDictionary<string, string> ToDictionary(KeyValuePair<string, string>[] v)
{
return v.ToDictionary();
}