Let us say I have this code
string seachKeyword = \"\";
List sl = new List();
sl.Add(\"store\");
sl.Add(\"State\");
sl.Add(\"STAM
StringComparer.CurrentCultureIgnoreCase is a better approach instead of using indexOf.
The FindAll does enumeration of the entire list.
the better approach would be to break after finding the first instance.
bool found = list.FirstOrDefault(x=>String.Equals(x, searchKeyWord, Stringcomparison.OrdinalIgnoreCase) != null;
You can apply little trick over this.
Change all the string to same case: either upper or lower case
List searchResults = sl.FindAll(s => s.ToUpper().Contains(seachKeyword.ToUpper()));
The optimal solution will be to ignore the case when performing the comparison
List<string> searchResults = sl.FindAll(s => s.IndexOf(seachKeyword, System.StringComparison.OrdinalIgnoreCase) >= 0);
Below method will search your needed keyword and insert all searched items into a new list and then returns new list.
private List<string> serchForElement(string searchText, list<string> ListOfitems)
{
searchText = searchText.ToLower();
List<string> Newlist = (from items in ListOfitems
where items.ToLower().Contains(searchText.ToLower())
select items).ToList<string>();
return Newlist; }