Skip to content

Instantly share code, notes, and snippets.

@zubivan
Created July 10, 2019 13:58
Show Gist options
  • Save zubivan/29f25c7fe2a749a4cbf6383a60cfff42 to your computer and use it in GitHub Desktop.
Save zubivan/29f25c7fe2a749a4cbf6383a60cfff42 to your computer and use it in GitHub Desktop.
Destructuring example
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