Created
August 16, 2018 20:44
-
-
Save flq/9c09754c78988d88b5d48236b1fb25fc to your computer and use it in GitHub Desktop.
Some nice .NET snippets
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
.NET snippets | |
1. Deconstruct a regex match group collection |
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
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