csharp filter list

Code Example - csharp filter list

                
                        List<int> myList = GetListOfIntsFromSomewhere();

// This will filter out the list of ints that are > than 7, Where returns an
// IEnumerable<T> so a call to ToList is required to convert back to a List<T>.
List<int> filteredList = myList.Where( x => x > 7).ToList();
                    
                
 

how to filter a list in csharp

                        
                                using System;
using System.Collections.Generic;

var vals = new List<int> {-1, -3, 0, 1, 3, 2, 9, -4};

List<int> filtered = vals.FindAll(e => e > 0);

Console.WriteLine(string.Join(',', filtered));
                            
                        
 

Related code examples