Sobes.tech
Junior — Middle

Can you explain what is meant by the term 'Dictionary' in programming?

sobes.tech AI

Answer from AI

In programming, the term "Dictionary" refers to a data structure that stores key-value pairs. This allows for quick retrieval of a value by its unique key.

Features of a dictionary:

  • Keys are unique.
  • Values can be any objects.
  • Provides fast access, insertion, and deletion of elements.

In C#, the dictionary is implemented by the class Dictionary<TKey, TValue> from the System.Collections.Generic namespace.

Example of using a dictionary in C#:

using System.Collections.Generic;

var dictionary = new Dictionary<string, int>();
dictionary.Add("apple", 3);
dictionary["banana"] = 5;

int count = dictionary["apple"]; // Get value by key

if (dictionary.ContainsKey("banana")) {
    // Key exists
}
Can you explain what is meant by the term… - sobes.tech