首页 > Linux操作系统 > Linux操作系统 > 从实例级别调用扩展方法
static void Main(string[] args)
{
// int 类型被指定了一个新方法
int myInt = 12345678;
myInt.DisplayDefiningAssembly();
// DataSet也是
System.Data.DataSet ds = new System.Data.DataSet();
ds.DisplayDefiningAssembly();
// SoundPlayer也一样
System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
sp.DisplayDefiningAssembly();
// 为 int 类型新加的功能
Console.WriteLine("Value of myInt: {0}", myInt);
Console.WriteLine("After reversed: {0}", myInt.ReverseDigits());
// 测试重载的扩展方法
myInt.Foo();
myInt.Foo("This is the sample provided by SpadeQ!");
// 下面这个就不行了
bool b = true;
// b.Foo();
Console.ReadLine();
}
将上面这个Main方法添加到上面的类中,作为程序的入口方法,然后执行,可以看到下面的结果:
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12641349/viewspace-145389/ ,如需转载,请注明出处,否则将追究法律责任。