📜  c#字符串大写首字母扩展方法——C#代码示例

📅  最后修改于: 2022-03-11 14:49:18.391000             🧑  作者: Mango

代码示例1
public static class StringExtensions
{
    public static string FirstCharToUpper(this string input) =>
        input switch
        {
            null => throw new ArgumentNullException(nameof(input)),
            "" => throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)),
            _ => input.First().ToString().ToUpper() + input.Substring(1)
        };
}