如何将以下fieldList数组转换为Dictionary<string,column> (i.e. Dictionary of name property of column class as key and value property of dictionary as column object)
字典。
public class columninfo
{
public string name {get;set;}
public column[] fieldList {get;set;}
}
public class column
{
public string name {get;set;}
public string fieldname {get;set}
public string format {get;set;}
}
最佳答案
您可以为此使用linq lambda。
column[] columns = getColumninfo();
columns.ToDictionary(x => x.name, y => y);
通过添加
StringComparer.OrdinalIgnoreCase
,可以确保列名查找不区分大小写。columns.ToDictionary(x => x.name, y => y, StringComparer.OrdinalIgnoreCase);
关于c# - 如何将数组转换为字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42904329/