简体   繁体   English

如何使用linq和c#将字典串字符串转换为字符串和字符串的键值对数组

[英]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.

相关问题 C# - 将由&#39;=&#39;分隔的Key值对的字符串转换为Dictionary - C# - Convert a string of Key value pair separated by '=' to Dictionary C#将字符串拆分为数组,然后拆分为字典中的键值对 - C# split string to array then to key value pair in dictionary 如何使用 Linq 将 JSON 文件中两个不同位置的数据转换为 C# 字典中的键(字符串)和值(双精度)? - How to convert data from two different locations in JSON file to a key(string) and value(double) within a C# dictionary, using Linq? C#转换列表 <string> 到字典 <string, string> LINQ - C# Convert List<string> to Dictionary<string, string> LINQ C# - 将 XML 元素转换为串联字符串中的键值对 - C# - Convert XML elements to key value pair in a concatenated string 如何将字典转换为 C# 中的 JSON 字符串? - How do I convert a dictionary to a JSON String in C#? 如何转换字典 <string, object> 到字典 <string, string> 在C#中 - How to convert Dictionary<string, object> to Dictionary<string, string> in c# 转换字典 <string, myClass> 列出 <double[]> 使用C#LINQ - convert Dictionary<string, myClass> to List<double[]> using c# linq 如何转换List <string> 到字典 <string,string> 使用linq? - How to convert List<string> to Dictionary<string,string> using linq? 转换字典<string, list<string> &gt; 列出<string>带有连续键/值 c#</string></string,> - Convert Dictionary<string, List<string>> to List<string> with concat Key/Value c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM