我有以下內容: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