I have a little bit confusion b/w Dictionary and Array.When should we use the Dictionary.
I have a query that " I have some substrings like 'of' , 'on , 'at' , 'above', 'near' and so on. I want to check on each entery of a another string that this string contain any above substrings or not .Then what could i use a Array or a Dictionary to store these substrings"
Exa:
Dictionary<int, string> Substring = new Dictionary<int, string>();
Substring.Add(1, "of");
Substring.Add(2, "on");
Substring.Add(3, "obove");
Substring.Add(4, "at");
Substring.Add(5, "off");
string[] Substring_ = new String[5];
Substring_[0] = "of";
Substring_[1] = "on";
Substring_[2] = "above";
Substring_[3] = "at";
Substring_[5] = "off";
string Check = "of";
int Find=0;
//Method 1 By using a ARRAY//
foreach(string cnt in Substring_)
{
if(Check==cnt)
{
Find=1;
break;
}
}
//Method 2 By using a Dictionary//
Dictionary<int, string>.ValueCollection Val = Substring.Values;
foreach (string cnt in Val)
{
if (Check == cnt)
{
Find = 1;
break;
}
which method is good for point of view of complexity.