2017-03-20 2 views
0

변환하는 방법 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;} 
} 

답변

4

당신은 이것에 대한 LINQ 람다를 사용할 수 있습니다. StringComparer.OrdinalIgnoreCase을 추가하여

column[] columns = getColumninfo(); 
columns.ToDictionary(x => x.name, y => y); 

당신은 열 이름 조회가 대소 문자를 구분하지 있는지 확인 할 수 있습니다.

columns.ToDictionary(x => x.name, y => y, StringComparer.OrdinalIgnoreCase); 
3
fieldList.ToDictionary(c=>c.name, c=>c); 
+0

@TimSchmelter @TimSchmelter 당신은 부모 클래스의 이름을 가지고 있습니다. 그는 내부의 배열에 대해 물었습니다. –

관련 문제