Skip to content

Instantly share code, notes, and snippets.

@pawlos
Created January 3, 2017 20:07
Show Gist options
  • Save pawlos/73a95d4c3da1290d97f71ba40e46d3ee to your computer and use it in GitHub Desktop.
Save pawlos/73a95d4c3da1290d97f71ba40e46d3ee to your computer and use it in GitHub Desktop.
Code before null-propagation operator
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