从对象集合列表中获取属性值
我想使用对象集合的属性之一从对象集合中获取值属性。
使用 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"});
I want to get value property from object collection using one of property of object collection.
using Linq what will be the query on 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"});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它可以写为“
您也可以在
C: 驱动器
中找到LINQ 查询示例
”C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033
在
CSharpSamples.zip
中解压缩并构建项目,位于文件夹LinqSamples
中It can written as
Also you can find
LINQ Query samples
in yourC: drive
C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033
in that
CSharpSamples.zip
unzip and build the project, located in folderLinqSamples
您在寻找以下内容吗
are you looking for something as below
这就是您想要做的吗:
我对您的
SupplierSettings
有点怀疑,因为它似乎不是一个很好的 OOP 示例。您最好考虑对象设计而不是计算此查询。只是一个建议。Is this what you're trying to do:
I'm a little dubious about your
SupplierSettings
as it doesn't seem to be a very good example of OOP. It may be better that you think about your object design rather than work out this query. Just a suggestion.