Skip to content

Instantly share code, notes, and snippets.

@flq
Created August 16, 2018 20:44
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 flq/9c09754c78988d88b5d48236b1fb25fc to your computer and use it in GitHub Desktop.
Save flq/9c09754c78988d88b5d48236b1fb25fc to your computer and use it in GitHub Desktop.
Some nice .NET snippets
.NET snippets
1. Deconstruct a regex match group collection
public static class DeconstructExtensions
{
/// <summary>
/// Deconstruct the first two matched sub-groups of a regex match to directly
/// obtain the values
/// </summary>
/// <param name="groups">the regex match groups</param>
/// <param name="val0">value 1</param>
/// <param name="val1">value 2</param>
public static void Deconstruct(this GroupCollection groups, out string val0, out string val1)
{
// group 0 is always the full match
val0 = groups[1].Value;
val1 = groups[2].Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment