Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
List<int> MyList = new List<int>() { 1, 2, 32, 32, 32, 32, 32, 3, 2, 64, 654, 5, 4, 54, 54, 54, 58, 45, 84, 54 };
           
            var lst = MyList.where(p=> p. ??? == 2)



how can i write lambada to generic lists or arrays with one field or column
Posted

1 solution

Try:
C#
List<int> MyList = new List<int>() { 1, 2, 32, 32, 32, 32, 32, 3, 2, 64, 654, 5, 4, 54, 54, 54, 58, 45, 84, 54 };

var lst = MyList.Where(p => p == 2);
List<int> list = MyList.Where(p => p == 2).ToList();
int[] array = MyList.Where(p => p == 2).ToArray();
 
Share this answer
 
Comments
noahdi 17-Aug-14 11:15am    
thanks, i works. i thought there should be a dot after p
OriginalGriff 17-Aug-14 11:20am    
Only if you want to use a property or method of the lambda parameter:

string[] list = GetStrings();
var x = list.Where(s => s.Length > 20);

Since an int doesn't have any properties, and limited methods... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900