1

How to convert below fieldList array to dictionary as 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;}
}
0

2 Answers 2

6

You can use a linq lambda for this.

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

By adding StringComparer.OrdinalIgnoreCase you can ensure that the column name lookup is case insensitive.

columns.ToDictionary(x => x.name, y => y, StringComparer.OrdinalIgnoreCase);
Sign up to request clarification or add additional context in comments.

Comments

3
fieldList.ToDictionary(c=>c.name, c=>c);

1 Comment

@TimSchmelter you're taking about the name of the parent class, he asked about the array inside

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.