Skip to content

Instantly share code, notes, and snippets.

@bleroy
Created June 29, 2020 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleroy/4f11eabdef608d10fbff2fcea9a1ebb0 to your computer and use it in GitHub Desktop.
Save bleroy/4f11eabdef608d10fbff2fcea9a1ebb0 to your computer and use it in GitHub Desktop.
public static class Util
{
/// <summary>
/// An extension method that enables the deconstruction of dictionary entries.
/// </summary>
/// <example>
/// ```cs
/// foreach ((string key, Foo value) in someDictionaryOfFoos)
/// {
/// // Do something with `key` and `value`...
/// }
/// ```
/// </example>
/// <param name="kvp">The key value pair to deconstruct.</param>
/// <param name="key">The deconstructed key.</param>
/// <param name="value">The deconstructed value.</param>
internal static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> kvp, out TKey key, out TValue value)
{
key = kvp.Key;
value = kvp.Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment