GetLength(this string str)参数加前this有什么用?

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

int length = “abc”.GetLength();
// 结果 length 为3

你可能感兴趣的:(GetLength(this string str)参数加前this有什么用?)