Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
2.2 Basic types: Dictionary
//2.2 Basic types: Dictionary using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Second most used type is Dictionary //Dictionary is a list of Key, Value pairs, where key must be unique Dictionary<int, string> dic = new Dictionary<int, string>(); //same as //Dictionary<int, string> dic = new Dictionary<int, string>() //{ // {5, "five"}, // {6, "six"} //}; dic[5] = "five"; //O(1) if space need not to be allocated, O(n) otherwise dic[6] = "six"; Console.WriteLine(dic[5]); //O(1) Console.WriteLine(dic.ContainsKey(6)); //O(1) dic.Keys.Where(f => f > 5) .ToList() .ForEach(f => Console.WriteLine(dic[f]+" ")); //or dic.Where(f => f.Key > 5) .Select(f => f.Value) .ToList() .ForEach(f => Console.WriteLine(f + "")); } } }
run
|
edit
|
history
|
help
0
Cotton Farm
4647
Fórum ➡ DataTable #1's rows that are NOT present in DataTable #2 ♦
hacker
Numeric to graphical styling using String Extension method
StringBuilder
Binary search tree - Pre-order Traversal
Get Round of 5 c# Vishal
services
megha