Dictionary in C#

 Introduction:

Dictionary in C# is a generic collection of Key and Value pair of data, we mainly use dictionary for maintaining a value for a particular,

An example of that would be a phone directory, where we maintain a phone number against a particular entity.

Dictionary in c# comes under a namespace which is System.Collections.Generics and we must have to import this namespace in order to use dictionary in C#.

We can have a dictionary with of two different data types, like we can have different data types for Key and its corresponding value. 

Here we will see how we can implement dictionary in C# with carious examples.

So first up creating a new console based application project in Visual Studio 2017.

So, we can declare a dictionary in C# as,

Dictionary<string,string>myDictionary=new Dictionary<string,string>();

So, we are considering an example of creating a dictionary where we are saving employees data with their job designations and occupations.


It will show the output as ,


Example 2:

In this second example, we will see that how can we update or remove any dictionary item using the c# dictionary,


Now we will see the output window by pressing crtl+F5






Talha Mahmood

I have been developing Applications in Microsoft .NET technologies since 2015, and having more then 5 years of experience in .NET Technology and SQL database, also having hands in tools like C# Windows Forms, WPF, WCF, Asp.Net Web forms, Asp.Net Core, SSRS, LINQ, Entity Framework, Crystal Reports, SQL server, MySQL, MongoDB, Document DB, JQuery, JavaScript, Oracle, Web API.

Post a Comment

Previous Post Next Post