C#扩展方法首字符大写转换

扩展string方法,将字符串的第一个字母转换为大写的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;

public static class ExtensionMethods
{
public static string UppercaseFirstLetter(this string value)
{
// Uppercase the first letter in the string.
if (value.Length > 0)
{
char[] array = value.ToCharArray();
array[0] = char.ToUpper(array[0]);
return new string(array);
}
return value;
}
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×