What will happen,if we run below code?

Dim dict As New Dictionary(Of String, Integer)
dict.Add("1", 100)
dict.Add("1", 200)

 Posted by Rajesh_Kumar on 1/17/2014 | Category: ASP.NET Interview questions | Views: 654 | Points: 40
Answer:

When we run above code,then it will throw an error saying that

An item with the same key has already been added.

Because we know that Dictionary have Unique key,it can not be Duplicate.

Always check if key is duplicate:

if (!dict_names.ContainsKey("Key"))

{
//add keys into Dictionary
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response