我将在前言中对LINQ非常新。我试图通过我的LINQ查询做一个简单的contains
。以下是我的询问:
myList.AddRange(oGal.AddressEntries.Cast<Outlook.AddressEntry>().Select(
x => new ListDetails
{
Id = val,
Name = x.Name
}).Take(400));
现在我正在使用Top 400
,但实际上只想在我的列表中添加包含#
的对象。有人能指出我如何实现这个目标吗?
答案 0 :(得分:4)
我想你只想查看名字所在的位置#就像你说的那样
myList.AddRange(oGal.AddressEntries.Cast<Outlook.AddressEntry>()
.Where( x => x.Name.Contains("#").Select(
x => new ListDetails
{
Id = val,
Name = x.Name
})));
答案 1 :(得分:4)
这应该这样做,使用contains in where method:
myList.AddRange(oGal.AddressEntries.Cast<Outlook.AddressEntry>()
.Where(x => x.Name.Contains("#"))
.Select(
x => new ListDetails
{
Id = val,
Name = x.Name
}));
答案 2 :(得分:4)
的内容
myList.AddRange(oGal.AddressEntries.Cast<Outlook.AddressEntry>()
.Where(i=>i.Name.Contains("#"))
.Select(
x => new ListDetails
{
Id = val,
Name = x.Name
}).Take(400));