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 matter which type of data source is used. In this article, we will learn how to print those names contains ‘MAN’ substring from the given array using LINQ. So to do our task we use Contains() method in the Where() method.
Where(employee => employee.Contains("MAN"))
Here, the Contains() method is used to check whether the given string contains the “MAN” word in it or not, and then the Where() method filters the array accordingly.
Input : [("MANVITHA"),("SRIMANTH"),("RAVI"),("MANASA"),("MOUNIKA")("MANAS");] Output : [("MANVITHA"),("SRIMANTH"),("MANASA"),("MANAS")] Input : [("bobby"),("ramya"),("sairam");] Output : No Output
To print the list of names contains “MAN” as a substring follow the following steps:
- Create a list(i.e., XEmployee) that will holds the name of the employees.
- Add the names to the list.
- Now find the names whose contains “MAN” as a substring by using XEmployee.Where(employee => employee.Contains(“MAN”))
- Display the employee names.
Names that contain MAN substring: MANVITHA SRIMANTH MANASA MANAS
Please Login to comment...