TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pankaj Kumar Choudhary
71
26.6k
13.5m
Dictionary
Feb 19 2015 11:21 AM
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.
Reply
Answers (
1
)
create patten using C#
Email Validation