Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Working with Dictionaries (csharp)
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here Console.WriteLine("Hello, world!"); Dictionary<string, int> myDict = new Dictionary<string, int>() { {"car", 20}, {"bus", 8}, {"lorries", 10} }; myDict.Add("bicycles", 5); foreach (KeyValuePair<string, int> pair in myDict) { Console.WriteLine(string.Format("{0}, {1}", pair.Key, pair.Value)); } foreach (var pair in myDict) { Console.WriteLine(string.Format("{0}, {1}", pair.Key, pair.Value)); } if (myDict.ContainsKey("bicycles")) { Console.WriteLine(string.Format("myDict contains bicycles!")); } if (myDict.ContainsValue(20)) { foreach (var pair in myDict) { if (pair.Value == 20) Console.WriteLine(string.Format("value 20 belongs to the key \"{0}\"",pair.Key)); } } int getValue; // this is a test that returns true/false if the key exists or not // if it exists, it will output the value and put it into getValue Console.WriteLine(myDict.TryGetValue("monster", out getValue)); if (myDict.TryGetValue("car", out getValue)) { Console.WriteLine(string.Format("myDict[\"car\"] is {0}", getValue)); Console.WriteLine(string.Format("myDict[\"car\"] is {0}", myDict["car"])); } } } }
run
|
edit
|
history
|
help
0
Simple Parallel.For example
Guid Formatting Code Snippet
V5
Classes
filter distinct items from the array without builtin function - Seeni
zmeika
dsdsdsdsd
Sum Matrix Column
KeyValue pair C#
test