Skip to content

Instantly share code, notes, and snippets.

@kyle-seongwoo-jun
Created December 19, 2019 00:59
Show Gist options
  • Save kyle-seongwoo-jun/84fedd63a68d8737e8b420ab2059f994 to your computer and use it in GitHub Desktop.
Save kyle-seongwoo-jun/84fedd63a68d8737e8b420ab2059f994 to your computer and use it in GitHub Desktop.
Deconstructing KeyValuePair
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