Efficient way to search List of String Arrays in C# -


i have structure this,

string[] variable1= new string["abc", "fss" , "fsfs", "gdgdds"]; string[] variable2= new string["sa", "gs" , "qe", "hf"];   static list<string[]> alllist = new list<string[]>();;  alllist .add(variable1); alllist .add(variable2); 

when string provided want search alllist , provide result array if found .

any archiving in efficient way?

both provided solutions run in linear time, way slow if have lots of words , make lots of queries.

you can use dictionary. dictionary uses hash table internally , much, faster.

to put strings in dictionary, can do:

dictionary<string, string[]> dict = new dictionary<string, string[]>(); foreach(string[] arr in alllist)     foreach(string str in arr)         dict[str] = arr; 

and can search it:

string s = "abc"; if(dict.containskey(s))     // result dict[s] else     // string not in array 

hope helps!


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -