This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 10: add a tuple | |
// This is just a dummy class that we can use in the example | |
public class City | |
{ | |
public City(string name, int population, string country) | |
{ | |
Name = name; | |
Population = population; | |
Country = country; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 11: add with params | |
// Use params to take several ints, each representing 3 digits | |
public static void Add<TKey>(this IDictionary<TKey, int> dictionary, TKey key, params int[] values) | |
=> dictionary.Add(key, values.Aggregate(0, (s, v) => s*1000 + v)); | |
// Now we can write it like this | |
var populations = new Dictionary<string, int> | |
{ | |
{ "China", 1,409,517,397 }, |
OlderNewer