Filter List of strings by Starting word

List<T> are a very commonly used in C# to store large amount of data. We may need to filter the data contained in a List. Let’s take a List<string> if we need to filter all those items which start from a specific word we can use StartsWith method to get all those items which start with word “A”.

List<string> Fruits = new List<string>() { "Apple", "Mango", "Orange","Apricot" };
var MyFruits = Fruits.FindAll(x => x.StartsWith("A"));

This will result in following

Apple

Apricot

Comments

Popular posts from this blog

Check if ViewBag is null or doesn't exist

Using Progress Bar In C#

Jquery serer side datatables in asp.net