类扩展方法

2020-06-12  本文已影响0人  价值投机168

代码:

class A
{
    public int aa = 12;
}
static class B
{
    public static int test(this A a)
    {
        return a.aa = a.aa + 10;
    }
}
class Program
{
    static void Main(string[] args)
    {
        var v = new A();
        Console.WriteLine(v.test());
        Console.Read();
    }
}

代码讲解:


image.png
上一篇 下一篇

猜你喜欢

热点阅读