Created
January 18, 2017 17:22
-
-
Save miguelerm/d1a65ebe1e813b5340b98d35c4ab8a0c to your computer and use it in GitHub Desktop.
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 StringExtensions { | |
| public static string Or(this string text, string alternativeText = "") { | |
| return string.IsNullOrWhiteSpace(text) ? alternativeText : text; | |
| } | |
| } | |
| /* | |
| Ejemplo: | |
| string texto = null; | |
| Console.WriteLine(texto.Or("(vacío)")); | |
| texto = ""; | |
| Console.WriteLine(texto.Or("(vacío)")); | |
| texto = " "; | |
| Console.WriteLine(texto.Or("(vacío)")); | |
| texto = "xxx"; | |
| Console.WriteLine(texto.Or("(vacío)")); | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment