100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Everything you need to know for Dictionary in C#.

Rating
-
Sold
-
Pages
3
Uploaded on
01-03-2022
Written in
2021/2022

Provides the basics of understanding and implementing a Dictionary in C#.









Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
March 1, 2022
Number of pages
3
Written in
2021/2022
Type
Class notes
Professor(s)
None
Contains
All classes

Content preview

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);
R151,00
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
21615442

Get to know the seller

Seller avatar
21615442 Durban University of Technology
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
3 year
Number of followers
0
Documents
1
Last sold
-

0,0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions