public static int GetLength(this string str) { return Encoding.Default.GetBytes(str).Length; }
该方法为扩展方法 this表示方法使用的参数即调用对象本身 int length = “abc”.GetLength(); // 结果 length 为3
public static int GetLength(this string str) { return Encoding.Default.GetBytes(str).Length; }
该方法为扩展方法 this表示方法使用的参数即调用对象本身 int length = “abc”.GetLength(); // 结果 length 为3