C# Dictionary Get Specific Key Value Code Example


Example: access dic by key c#

using System; using System.Collections.Generic;  class Program {     static void Main()     {         Dictionary<string, int> dictionary = new Dictionary<string, int>();          dictionary.Add("apple", 1);         dictionary.Add("windows", 5);          // See whether Dictionary contains this string.         if (dictionary.ContainsKey("apple"))         {             int value = dictionary["apple"];             Console.WriteLine(value);         }          // See whether it contains this string.         if (!dictionary.ContainsKey("acorn"))         {             Console.WriteLine(false);         }     } }

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android SDK Location Should Not Contain Whitespace, As This Cause Problems With NDK Tools