Creating the IEnumerable> Objects with C#?

前端 未结 5 1502
野趣味
野趣味 2020-12-25 11:01

For testing purposes, I need to create an IEnumerable> object with the following sample key value pairs:



        
5条回答
  •  不知归路
    2020-12-25 11:40

    any of:

    values = new Dictionary { {"Name", "John"}, {"City", "NY"} };
    

    or

    values = new [] {
          new KeyValuePair("Name","John"),
          new KeyValuePair("City","NY")
        };
    

    or:

    values = (new[] {
          new {Key = "Name", Value = "John"},
          new {Key = "City", Value = "NY"}
       }).ToDictionary(x => x.Key, x => x.Value);
    

提交回复
热议问题