C# Program to Demonstrate the Use of the Method as a Condition in the LINQ Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matter which type of data source is used. In this article, we will demonstrate how to use the method as a condition by taking the example of employee data in which the employee's name that contains less than four characters in their name. So to this task, we use Where() function. This function filters the given array according to the given condition. Or we can say that Where() method returns the value from the sequence based on the specified criteria. Example: Input : [("m"), ("srav"), ("a"), ("gopi"), ("bai")("sai")] Output : [("m"), ("a"), ("bai"), ("sai")] Input : [("bobby"), ("ramya"), ("sairam")] Output : No Output Approach To print the list of employees whose name contains less than 4 characters follow the following steps: Create a function named "checkstring" which check the length of the string is less than 4 characters.i.e., str.Length < 4.Create a list(i.e., XEmployee) that will contain the name of the employees.Add the employee names to the list.Now find the employee names whose length is less than 4 characters by using "data.Where(employee => checkstring(employee))".Display the employee names. Example: C# // C# program to illustrate the use of // the method as a condition in the // LINQ where() method of the list collection using System; using System.Collections.Generic; using System.Linq; class GFG{ // Function to check the given string is less than 4 static bool checkstring(string str) { if (str.Length < 4) return true; else return false; } static void Main(string[] args) { // Define a list List<string> XEmployee = new List<string>(); // Add names into the list XEmployee.Add("m"); XEmployee.Add("srav"); XEmployee.Add("a"); XEmployee.Add("gopi"); XEmployee.Add("bai"); XEmployee.Add("sai"); // Choose the employee whose name length is // less than 4 letters IEnumerable<string> result = XEmployee.Where( employee => checkstring(employee)); Console.WriteLine("Name of the Employees are: "); // Display employee names foreach (string stname in result) { Console.WriteLine(stname); } } } Output: Name of the Employees are: m a bai sai Comment More infoAdvertise with us Next Article C# | Check if an array contain the elements that match the specified conditions G gottumukkala_sivanagulu Follow Improve Article Tags : C# CSharp LINQ CSharp-programs Similar Reads C# | How to get all elements of a List that match the conditions specified by the predicate List<T>.FindAll(Predicate<T>) Method is used to get all the elements that match the conditions defined by the specified predicate. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot.List class can accept null as a valid value for refe 3 min read C# | Remove all elements of a List that match the conditions defined by the predicate List<T>.RemoveAll(Predicate<T>) Method is used to remove all the elements that match the conditions defined by the specified predicate. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot. List class can accept null as a valid value fo 3 min read C# | How to check whether a List contains the elements that match the specified conditions List<T>.Exists(Predicate<T>) Method is used to check whether the List<T> contains elements which match the conditions defined by the specified predicate. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot.List class can accept n 3 min read C# Program to Print the Employees Whose Name Contains Less Than 4 Characters Using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 2 min read C# | Check if an array contain the elements that match the specified conditions Array.Exists(T[], Predicate<T>) Method is used to check whether the specified array contains elements that match the conditions defined by the specified predicate. Syntax: public static bool Exists<T> (T[] array, Predicate<T> match); Parameters: array: It is a one-dimensional, zero 3 min read C# Program to Print the Names that Contain 'MAN' Substring Using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 2 min read Like