How to initialize a dictionary containing lists of dictionaries?

前端 未结 3 1585
一向
一向 2020-12-29 22:01

I am starting to do a little development in C#, and I am stuck with a problem here. Usually I develop in Python where stuff like this is being implemented easily (at least f

3条回答
  •  不思量自难忘°
    2020-12-29 22:37

    IMHO the more elegant way to do this in c#, to avoid this use of the Dictionary, c# has better options than that,

    is to create a class (or struct) like Person

    public class Person 
    {
        public Person() { }
    
        public string Name {get;set;}
        public int Age {get;set;}
        public double Height {get;set;}
    }
    

    and put those objects in a generic list or collection that implements IEnumerable

    public List;
    

    And use Linq to get the person you want

    var personToLookfor =
        from p in people
        where p.Name == "somename"
        select p;
    

提交回复
热议问题