How to implement incremental search on a list

前端 未结 7 2083
无人共我
无人共我 2021-02-06 04:52

I want to implement incremental search on a list of strings. Consider I have an array containing which contains the strings store,state,stamp,crawl,crow. My application has a te

7条回答
  •  北海茫月
    2021-02-06 05:28

    Instead of an array of strings you could use a generic collection. This way you can use the FindAll method with a delegate to search through the items.

    string searchString = "s";
    List sl = new List();
    sl.Add("store");
    sl.Add("state");
    sl.Add("stamp");
    sl.Add("crawl");
    sl.Add("crow");
    List searchResults = sl.FindAll(delegate(string match) 
                                                    { 
                                                        return   match.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase); 
                                                    });
    

提交回复
热议问题