Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Palindrome 1
Problem: on_off
DateTime
Polygon Util
int array element change with xor
n th to last element
Math 9.6
Testing 004
SVNParse
matching parenthesis
Please log in to post a comment.