c# dictionary array code example

Example 1: array list dictionary c#

using System.Collections.Generic;

List<string> myList = new List<string>();

myList.Add("Hello");
myList.Add("World");
myList.Add(10); // Compiler Error

Example 2: array list dictionary c#

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        Dictionary<string, int> myDictionary = new Dictionary<string, int>();

        myDictionary.Add("bob", 27);
        myDictionary.Add("fred", 33);

        int theAge = myDictionary["bob"];
    }
}