出于测试目的,我需要IEnumerable<KeyValuePair<string, string>>使用以下示例键值对创建对象:
Key = Name | Value : John
Key = City | Value : NY
Run Code Online (Sandbox Code Playgroud)
这样做最简单的方法是什么?
Mar*_*ell 55
任何:
values = new Dictionary<string,string> { {"Name", "John"}, {"City", "NY"} };
Run Code Online (Sandbox Code Playgroud)
要么
values = new [] {
new KeyValuePair<string,string>("Name","John"),
new KeyValuePair<string,string>("City","NY")
};
Run Code Online (Sandbox Code Playgroud)
要么:
values = (new[] {
new {Key = "Name", Value = "John"},
new {Key = "City", Value = "NY"}
}).ToDictionary(x => x.Key, x => x.Value);
Run Code Online (Sandbox Code Playgroud)
var List = new List<KeyValuePair<String, String>> {
new KeyValuePair<String, String>("Name", "John"),
new KeyValuePair<String, String>("City" , "NY")
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34634 次 |
| 最近记录: |