出于测试目的,我需要创建一个的IEnumerable< KeyValuePair<字符串,字符串>>在下面的示例键值对
目标:
For testing purposes, I need to create an IEnumerable<KeyValuePair<string, string>>
object with the following sample key value pairs:
Key = Name | Value : John
Key = City | Value : NY
什么是做到这一点的最简单的方法呢?
What is the easiest approach to do this?
任何的:
values = new Dictionary<string,string> { {"Name", "John"}, {"City", "NY"} };
或
values = new [] {
new KeyValuePair<string,string>("Name","John"),
new KeyValuePair<string,string>("City","NY")
};
或
values = (new[] {
new {Key = "Name", Value = "John"},
new {Key = "City", Value = "NY"}
}).ToDictionary(x => x.Key, x => x.Value);