我想使用对象集合的属性之一从对象集合中获取值属性。

使用Linq什么是SupplierSettingsList上的查询

public class SupplierSettings
{
    private string Key;
    private SupplierSettingsPropertyEnum property;
    private string Value;
}

List<SupplierSettings> SupplierSettingsList =new List<SupplierSettingsDto>();

SupplierSettingsList .Add
(new SupplierSettings{Key="1",property=SupplierSettingsPropertyEnum.Name,Value="Name"});

SupplierSettingsList .Add
(new SupplierSettings{Key="2",property=SupplierSettingsPropertyEnum.StartTime,Value="7PM"});

SupplierSettingsList .Add
(new SupplierSettings{Key="3",property=SupplierSettingsPropertyEnum.EndTime,Value="10PM"});

SupplierSettingsList .Add
(new SupplierSettings{Key="4",property=SupplierSettingsPropertyEnum.Interval,Value="45"});

最佳答案

它可以写成

var results = from o in SupplierSettingsList
              where o.property == SupplierSettingsPropertyEnum.Interval
              select o.Value;


您也可以在LINQ Query samples中找到C: drive
C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033
在该CSharpSamples.zip解压缩并生成位于文件夹LinqSamples中的项目

10-04 12:52