How to use ienumerable and linq where condition to filter a list in C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Collections.Generic;
 
class Program
{
    static void Main() {
        List<string> list = new List<string> { "c#", "c", "java", "python", "c++", "go", "php" };

        IEnumerable<string> query = list.Where(str => str.Length < 3);

        foreach (string s in query) {
            Console.WriteLine(s);
        }
    }
}
 
 
 
 
/*
run:
 
c#
c
go
 
*/

 



answered Aug 19, 2023 by avibootz
...