Create a new list from the old list using the lambda function

I have the following: List<InputRow>which contains several InputRow objects.

I am wondering if there is a way to use the lambda function in my source list to give me a new list where InputRow.someProperty > 1for all objects.

This will leave me with a list of InputRow objects that have someProperty greater than 1.

+3
source share
4 answers

You can use LINQ (connection .Where()and .ToList () ):

List<InputRow> originalList = ...
List<InputRow> filteredList = originalList
    .Where(x => x.someProperty > 1)
    .ToList();
+6
source

You can also do this:

var list = new List<string>(){ "a", "b", "c" };

list.RemoveAll(s => s == "b");

which removes items in place instead of creating a new list.

+7
source

. :

var newList = inputRowList.Where(inputRow => inputRow.someProperty > 1).ToList();
+3
List<InputRow> newlist = oldlist.Where(x => x.someProperty > 1).ToList();

, someProperty > 1 .ToList()

+2

All Articles