use the name of the field instead of index in list array in C#

后端 未结 3 1475
盖世英雄少女心
盖世英雄少女心 2021-01-28 17:13

I have a getvalue object that contains a price list which consists of 5 items. I need to get the value of one of the elements. I can get the value by index:

<
3条回答
  •  日久生厌
    2021-01-28 17:24

    You can either change your array to Dictionary or use LINQ to perform linear search for your object by name:

    return getValue1.ValuationPrices.First(x => x.Name == "myName").Value.ToString();
    

提交回复
热议问题