Created
July 10, 2019 13:58
-
-
Save zubivan/29f25c7fe2a749a4cbf6383a60cfff42 to your computer and use it in GitHub Desktop.
Destructuring example
This file contains 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
public static class Example | |
{ | |
public void Main() | |
{ | |
var (key, value) = new KeyValuePair<string, bool>("example", true); | |
var dictionary = new Dictionary<string, bool>(); | |
foreach (var (k, v) in dictionary) | |
{ | |
// do something with k and v here | |
} | |
} | |
} | |
public static class KeyValuePairExtensions | |
{ | |
public static void Deconstruct<TKey, TValue>( | |
this KeyValuePair<TKey, TValue> pair, | |
out TKey key, | |
out TValue value) | |
{ | |
key = pair.Key; | |
value = pair.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment