[英]how do i convert Dictionary string string to array of key value pair of string and string using linq and c#
I have a schema generated from BizTalk. 我有一个从BizTalk生成的模式。 it doesn't understand the dictionary collection so it simply converts that to array of key value pair of string and string.
它不理解字典集合,因此它只是将其转换为字符串和字符串的键值对数组。 Now when i am redirecting the request in a service i get
现在,当我在服务中重定向请求时,我得到了
Dictionary<string, string> valuePairs
When i looked in to the reference.cs file i can see like this: 当我查看reference.cs文件时,我可以看到如下:
public bool ProcessMessage(string code, string template, Service.Proxy.ArrayOfKeyValueOfstringstringKeyValueOfstringstring[] valuePairs)
How can i convert this dictionary to array of key value of string string using linq? 如何使用linq将此字典转换为字符串字符串键值数组? I know it's easy to do this using linq but any help will really be appreciated.
我知道使用linq很容易做到这一点,但真的很感激任何帮助。
I have so far tried this but doesn't work: 到目前为止我试过这个但是没有用:
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[] array =
valuePairs.Select(pair => string.Format("{0},{1}", pair.Key, pair.Value))
.ToArray(KeyValuePair<string,string>);
try below , you may need to change the set properties of new object accordingly 尝试下面,您可能需要相应地更改新对象的设置属性
ArrayOfKeyValueOfstringstringKeyValueOfstringstring[] array =
valuePairs.Select(pair =>
new ArrayOfKeyValueOfstringstringKeyValueOfstringstring(){
Key= pair.Key, Value= pair.Value}).ToArray();
你可以做的是将你的字典转换为所需的数组:
KeyValuePair<string, string>[] kvps = valuePairs.ToArray();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.