C# 扩展方法用于非继承的扩展类的内置方法 比如给 String 扩展一个方法:

1
2
3
4
5
6
7
8
9
10
11
namespace ExtensionMethods
{
public static class MyExtensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' },
StringSplitOptions.RemoveEmptyEntries).Length;
}
}
}

扩展方法无法访问扩展类中的私有变量 类似于 DoTween 中可以直接在 transform 后面调用方法的也是基于扩展方法

更新于

请我喝[茶]~( ̄▽ ̄)~*

Solvarg 微信支付

微信支付

Solvarg 支付宝

支付宝

Solvarg 贝宝

贝宝