How to implement incremental search on a list

前端 未结 7 2097
无人共我
无人共我 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<string> sl = new List<string>();
    sl.Add("store");
    sl.Add("state");
    sl.Add("stamp");
    sl.Add("crawl");
    sl.Add("crow");
    List<string> searchResults = sl.FindAll(delegate(string match) 
                                                    { 
                                                        return   match.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase); 
                                                    });
    
    0 讨论(0)
提交回复
热议问题