Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding items to Dictionary without using Add method in C#

Tags:

c#

dictionary

I have items and I want to add them to Dictionary Without using Add method (because it consumes number of lines). Is there any way to add items to Dictionary like

new List<string>() { "P","J","K","L","M" };

or like AddRange Method in List. Any help will be highly appericiated.

like image 617
yo chauhan Avatar asked Sep 28 '26 11:09

yo chauhan


1 Answers

Referenced from here

 Dictionary<int, StudentName> students = new Dictionary<int, StudentName>()
 {
   { 111, new StudentName {FirstName="Sachin", LastName="Karnik", ID=211}},
   { 112, new StudentName {FirstName="Dina", LastName="Salimzianova", ID=317}},
   { 113, new StudentName {FirstName="Andy", LastName="Ruth", ID=198}}
};
like image 50
tsukimi Avatar answered Sep 30 '26 23:09

tsukimi