Created
December 19, 2019 00:59
-
-
Save kyle-seongwoo-jun/84fedd63a68d8737e8b420ab2059f994 to your computer and use it in GitHub Desktop.
Deconstructing KeyValuePair
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
static class KeyValuePairExtensions | |
{ | |
public static void Deconstruct<TKey, TValue>( | |
this KeyValuePair<TKey, TValue> kvp, | |
out TKey key, | |
out TValue value) | |
{ | |
key = kvp.Key; | |
value = kvp.Value; | |
} | |
} | |
var dictionary = new Dictionary<int, string> { ... }; | |
foreach ((int key, string value) in dictionary) | |
{ | |
// do something with the key and value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment