如何将List 转换成C#中的Dictionary >?
问题描述:
我有
Class
属性String
和List<String>
。我想将此List<Class>
转换为Dictionary<String, List<String>>
,但我无法做到这一点。如何直接转换List<Class>
为Dictionary?
如何将List <Class>转换成C#中的Dictionary <string,List <String>>?
public class SerializationClass
{
string key;
List<string> values;
public SerializationClass()
{
}
public string Key
{
get
{
return this.key;
}
set
{
this.key = value;
}
}
public List<string> Values
{
get
{
return this.values;
}
set
{
this.values = value;
}
}
public SerializationClass(string _key, List<string> _values)
{
this.Key = _key;
this.Values = _values;
}
}
和列表的人口,
List<SerializationClass> tempCollection = new List<SerializationClass>();
在这里,我要转换为转换tempCollection
到Dictionary
Dictionary<string, List<string>> tempDict = new Dictionary<string, List<string>>(tempCollection.Count);
tempCollection有转换为tempDict?
欣赏您的回复。
谢谢,并问候,
阿迈勒拉杰。
你尝试过什么什么会失败?.. –