C#
Dictionary.
Difference between an array and a dictionary.
An array stores a list of objects and a dictionary store key-value pair.
Key-value pair (KVP).
Is a set of two linked data items, a key which is a unique identifier for some item
of data, and the value.
Example.
Sam,9712
Maps is the concept that provides the functionality to map the value with the key
inside the dictionary.
To initialise the basic commands in c# must have the below.
using System.Collections.Generic;
Dictionary < string, => This initialises the dictionary value and classes it as a
string.
string > phonebook = new Dictionary < string, => This sets the Dictionary value to
be named as phonebook.
string > (); => This closes the initialisation of dictionary.
Storing the values into the Dictionary (in this case the dictionary is treated as an array).
//Create a dictionary and add names to the dictionary.
Dictionary<string, int> names = new Dictionary<string, int>();
names.Add("John Doe",45);
names.Add("Sammy", 50);
names.Add("Harry styles", 18);
Console.WriteLine("Sammy is "+ names["Sammy"]+ " years old.");
//Create a dictionary with a size to it.
Dictionary<int, double> numbers = new Dictionary<int,double>(5);
numbers.Add(1, 1000);
numbers.Add(2, 50);
numbers.Add(3, 800);
numbers.Add(4, 4);
numbers.Add(5, 900);
Dictionary.
Difference between an array and a dictionary.
An array stores a list of objects and a dictionary store key-value pair.
Key-value pair (KVP).
Is a set of two linked data items, a key which is a unique identifier for some item
of data, and the value.
Example.
Sam,9712
Maps is the concept that provides the functionality to map the value with the key
inside the dictionary.
To initialise the basic commands in c# must have the below.
using System.Collections.Generic;
Dictionary < string, => This initialises the dictionary value and classes it as a
string.
string > phonebook = new Dictionary < string, => This sets the Dictionary value to
be named as phonebook.
string > (); => This closes the initialisation of dictionary.
Storing the values into the Dictionary (in this case the dictionary is treated as an array).
//Create a dictionary and add names to the dictionary.
Dictionary<string, int> names = new Dictionary<string, int>();
names.Add("John Doe",45);
names.Add("Sammy", 50);
names.Add("Harry styles", 18);
Console.WriteLine("Sammy is "+ names["Sammy"]+ " years old.");
//Create a dictionary with a size to it.
Dictionary<int, double> numbers = new Dictionary<int,double>(5);
numbers.Add(1, 1000);
numbers.Add(2, 50);
numbers.Add(3, 800);
numbers.Add(4, 4);
numbers.Add(5, 900);