Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

dictionary string list int c#

//init
Dictionary<string, List<int>> dictionaryStringListOfInt = new Dictionary<string, List<int>>(){
                { "The First", new List<int>(){ 1,2 } },
                { "The Second", new List<int>(){ 1,2 } }
            };
//add a dictinary Key Value pair with a new empty list
//note you can add an existing list but be carful as it is a ref type and only pointing to ints (changes will be seen in original list ref)
dictionaryStringListOfInt.Add("The New", new List<int>());
//Add some values
dictionaryStringListOfInt["The New"].Add(1);
dictionaryStringListOfInt["The New"].Add(2);
//access some values via the Key and the values index
Console.WriteLine(dictionaryStringListOfInt["The New"][0]);//expected output 1
dictionaryStringListOfInt["The New"][0] = 3;
Console.WriteLine(dictionaryStringListOfInt["The New"][0]);//expected output 3
Console.WriteLine(dictionaryStringListOfInt["The New"][1]);//expected output 2
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# regex find last match 
Csharp :: c# read large file 
Csharp :: list min and Max value in c# 
Csharp :: static c# 
Csharp :: c# create excel file 
Csharp :: c# clear an array 
Csharp :: Reverse Coding Challenge 1 
Csharp :: c# implement ienumerable t 
Csharp :: Sort ListBox numerically in C# 
Csharp :: c# add 2 arrays 
Csharp :: asp.net core identity get all roles 
Csharp :: c# function 
Csharp :: how to use yield in c# 
Csharp :: autofac .net core 6 
Csharp :: unity respawn 
Csharp :: initialize a char array java 
Csharp :: prevent system shutdown c# 
Csharp :: get appsettings from app.config c# .net core 
Csharp :: callling class c# 
Csharp :: how to display array in string in c# 
Csharp :: c# sftp 
Csharp :: c# string 
Csharp :: how to fix on GetMouseButtonDown activating UI unity 
Csharp :: how to use double in c# 
Csharp :: how to use buildcontext in initstate flutter 
Csharp :: how to populate list in c# 
Csharp :: check if two date ranges overlap c# 
Csharp :: listview inter thread operation not valid 
Csharp :: int array to frequency dictionary c# 
Csharp :: c# array of objects 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =