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
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
foreach (string cnt in Val)
{
if (Check == cnt)
{
Find = 1;
break;
}
which method is good for point of view of complexity.

VulpesPosted Feb 19, 2015, 11:54 AM
Given a key, you can quickly find its associated value using a technique known as hashing though the underlying implementation is invisible to the C# programmer.
In an ordinary Dictionary, the key/value pairs are not stored in any particular order and, if you iterate through them, there's no guarantee that they will be returned in the same order they were added to the Dictionary.
However, there is something called a SortedDictionary which automatically sorts the key/value pairs in key order.
In contrast, an array is just an ordered collection of values of a given type. Once it's created an array remains fixed in size. You can access individual members of the array by their index (starting from zero) which is a very quick operation.
Arrays are the simplest and fastest of the collection types.
In the particular application you mention, an array should suffice if you're just wanting to see whether a word exists as part of a larger string.
However, if you want to count the occurrences of each word and store the result or replace a word with another word, then a Dictionary would be preferable.