c# dictionary literal initializer
C#
public class HowToDictionaryInitializer
{
class StudentName
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int ID { get; set; }
}
public static void Main()
{
var 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 } }
};
foreach(var index in Enumerable.Range(111, 3))
{
Console.WriteLine($"Student {index} is {students[index].FirstName} {students[index].LastName}");
}
Console.WriteLine();
var students2 = 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 }
};
foreach (var index in Enumerable.Range(111, 3))
{
Console.WriteLine($"Student {index} is {students2[index].FirstName} {students2[index].LastName}");
}
}
}
Also in C#:
- Title
- idbset sqlquery
- Category
- C#
- Title
- c# pull request
- Category
- C#
- Title
- c# bool list count true
- Category
- C#
- Title
- how to change player cursor c# script unity
- Category
- C#
- Title
- asp.net textarea disable resize
- Category
- C#
- Title
- c# resize bitmap
- Category
- C#
- Title
- c# delay
- Category
- C#
- Title
- find month number from date C#
- Category
- C#
- Title
- iframe set html content c#
- Category
- C#
- Title
- Unity how to put IEnumerator in update and loop once with yeild return new waitforseconds
- Category
- C#
- Title
- unity 2d joystick controls
- Category
- C#
- Title
- take screenshot in c#
- Category
- C#
- Title
- unity list
- Category
- C#
- Title
- why is c# say ; expected
- Category
- C#
- Title
- array copy c#
- Category
- C#
- Title
- No context type was found in the assembly
- Category
- C#
- Title
- automapper c# initialize error
- Category
- C#
- Title
- c# list to string
- Category
- C#
- Title
- file picker uwp c#
- Category
- C#
- Title
- leantween id
- Category
- C#
- Title
- c# quaternion eular calculator
- Category
- C#
- Title
- .net core copy file in folder to root
- Category
- C#
- Title
- grab reference from method parameter c#
- Category
- C#
- Title
- uinput dialog uwp c#
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- convert comma separated string to array c#
- Category
- C#
- Title
- C# Unknown column 'FundAllocation' in 'field list
- Category
- C#
- Title
- degree to radians c#
- Category
- C#
- Title
- navigate to another page with an object uwp c#
- Category
- C#
- Title
- c# webcam
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- c# public static string
- Category
- C#
- Title
- asp.net core timeout
- Category
- C#
- Title
- usermanager change password without current password
- Category
- C#
- Title
- unity gameobjects with tag
- Category
- C#
- Title
- how to delay something in c# unity
- Category
- C#
- Title
- c# split a string and return list
- Category
- C#
- Title
- how to remove vowels from a sttring using regex c#
- Category
- C#
- Title
- f string C#
- Category
- C#
- Title
- unity check tag
- Category
- C#
- Title
- c# find element in list of list
- Category
- C#
- Title
- uncaught syntaxerror invalid or unexpected token unity webgl
- Category
- C#
- Title
- c# generate random number
- Category
- C#
- Title
- unity ui not seen
- Category
- C#
- Title
- unity monobehaviour
- Category
- C#
- Title
- c# arraylist to listview
- Category
- C#
- Title
- how do loops on C#
- Category
- C#
- Title
- check version of asp.net core
- Category
- C#
- Title
- get enum value c#
- Category
- C#
- Title
- c# switch statement
- Category
- C#
- Title
- unity button interactable
- Category
- C#
- Title
- native-googlesignin configuration is null!?
- Category
- C#
- Title
- c# find duplicates in list
- Category
- C#
- Title
- convert string array to int C#
- Category
- C#
- Title
- list c#
- Category
- C#
- Title
- How to get number of months between 2 dates c#
- Category
- C#
- Title
- how to exit a program in c#
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- newtonsoft create dynamic object
- Category
- C#
- Title
- comments unity c#
- Category
- C#
- Title
- cursorlockmode cannot be used as a method C#
- Category
- C#
- Title
- how to go to other forms in C#
- Category
- C#
- Title
- how to hide a panel ui unity
- Category
- C#
- Title
- unity cast float to int
- Category
- C#
- Title
- asking for user input integer c#
- Category
- C#
- Title
- find mongodb c# with task T
- Category
- C#
- Title
- unity key detection
- Category
- C#
- Title
- zip file ignoring directory starting with dot
- Category
- C#
- Title
- mongodb custom IIdGenerator
- Category
- C#
- Title
- c# checksum
- Category
- C#
- Title
- how to detected WindowCloseEvent in other window wpf
- Category
- C#
- Title
- reference to gameobject in different scene unity
- Category
- C#
- Title
- value is null to insert in c#
- Category
- C#
- Title
- how to get length of okobjectresult c#
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- C# extend array
- Category
- C#
- Title
- c# check if string is in array
- Category
- C#
- Title
- how to reference function in unity
- Category
- C#
- Title
- dictionary c#
- Category
- C#
- Title
- what function is called just before the a script is ended c#
- Category
- C#
- Title
- .sh script: check if file exist
- Category
- C#
- Title
- copy a list C#
- Category
- C#
- Title
- array syntax c#
- Category
- C#
- Title
- POST http://localhost:5001/api/v1/identity/login 500 (Internal Server Error) LoginForm.jsx:39 Error: Request failed with status code 500 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad (xhr.js:61)
- Category
- C#
- Title
- linq foreach c#
- Category
- C#
- Title
- c# array isn't working
- Category
- C#
- Title
- c# get desktop path
- Category
- C#
- Title
- unity set object scale
- Category
- C#
- Title
- unity quaternion
- Category
- C#
- Title
- c# how to initialize an array
- Category
- C#
- Title
- c# find element by condition
- Category
- C#
- Title
- roulette algorithm genetic algorithm
- Category
- C#
- Title
- how to convert from hexadecimal to binary in c#
- Category
- C#
- Title
- unity vector3 smoothdamp not reaching target
- Category
- C#
- Title
- c# list string return concatenate
- Category
- C#
- Title
- c# MD5.Create returning nul
- Category
- C#
- Title
- C# linq mselect
- Category
- C#
- Title
- how to make error sound c#
- Category
- C#
- Title
- c# convert dictionary to anonymous object
- Category
- C#
- Title
- convert base64 string to string c#
- Category
- C#