Dictionary in C sharp. Please explain with code

What is a dictionary in C#?Please explain.

Below you can understand the use of the dictionary in an easy way.

The Dictionary type in the C# language provides fast lookups with keys to get values.
It allows you to use keys and values of any type, including ints and strings.
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        Dictionary <string, int> dictionary = new Dictionary<string, int>();
dictionary.Add(“cat”, 2);
dictionary.Add(“dog”, 1);
dictionary.Add(“llama”, 0);
dictionary.Add(“iguana”, -1);
dictionary.Add(“iguana”, -1);
    }
}

Leave a Comment

RSS
YouTube
YouTube
Instagram