通过所需的键从 IEnumerable <CustomModel>中提取值



我有带有两个属性的custommodel类:

public class CustomModel 
{
    public string Key { get; set; }
    public string Value { get; set; }
}

另外,我有IEnumerable<CustomModel>对象。假设该对象中有100个项目,其中一个具有Key = "Age",带有Value = "50"。如何仅从对象中提取该项目?实际上,我需要通过键"年龄"并获得值" 50"。

您是否正在寻找类似的东西: var dict = listOfModels.ToDictionary(x => x.Key, x => x.Value); var sample = dict["Age"] // should be 50

相关内容

最新更新