我有以下内容:List<InputRow>
其中包含一些InputRow对象。使用lambda函数从旧列表创建新列表
我想知道是否有方法让我在我的原始列表上使用lambda函数给我一个新列表,其中InputRow.someProperty > 1
为所有对象。
这将使我InputRow对象的列表均具有someProperty大于1
我有以下内容:List<InputRow>
其中包含一些InputRow对象。使用lambda函数从旧列表创建新列表
我想知道是否有方法让我在我的原始列表上使用lambda函数给我一个新列表,其中InputRow.someProperty > 1
为所有对象。
这将使我InputRow对象的列表均具有someProperty大于1
List<InputRow> newlist = oldlist.Where(x => x.someProperty > 1).ToList();
这将搜索您的旧列表,条件someProperty > 1
并将结果转换为列表使用.ToList()
当然。你可以这样做:
var newList = inputRowList.Where(inputRow => inputRow.someProperty > 1).ToList();
你当然也可以这样做:
var list = new List<string>(){ "a", "b", "c" };
list.RemoveAll(s => s == "b");
这地方删除而不是创建一个新的列表中的项目。
[使用LINQ删除列表中的对象](http://stackoverflow.com/questions/853526/using-linq-to-remove-objects-within-a-listt) –
2012-04-23 19:18:49