NateS NateS - 13 days ago 10
C# Question

How to pull the key value based on the key that is inside the Dictionary?

Let's say I did the following:

Dictionary<string,NetworkStream> dictionary = new Dictionary<string,NetworkStream>();
dictionary.add("Matt",network);
dictionary.add("Mike",network);
dictionary.add("Jack",network);


How do I pull the
Networkstream
of Jack? Assuming I have multiple of lines likes this.

UPDATE: I didn't explain myself well, sorry. If the name is already exists I'm not going to add him to the dictionary.. I meant if I have different names.

Answer

Dictionary cannot have more than one key with same name, still you can access the value of 'Jack' like this,

value = dictionary["Jack"];