Well, Mat's MugMat's Mug already gave the only improvement for the code in the extension-methodthe only improvement for the code in the extension-method I could find, using the conditional-member-access operator.
Aside from that, there's only the methods name. Which is far too long and awkward.
Truncate has a nice ring to it, and everybody understands it.
public static class StringExtensions
{
public static string Truncate(this string value, int maxLength)
{
return value?.Substring(0, Math.Min(value.Length, maxLength));
}
}