Created
January 3, 2017 20:07
-
-
Save pawlos/73a95d4c3da1290d97f71ba40e46d3ee to your computer and use it in GitHub Desktop.
Code before null-propagation operator
This file contains 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 string Truncate(string value, int length) | |
{ | |
string result = value; | |
if (value != null) // Skip empty string check for elucidation | |
{ | |
result = value.Substring(0, Math.Min(value.Length, length)); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment