代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Practice_MyExtensions
{
class Program
{
static class MyExtensions
{
//本方法允许任何对象显示它所处的程序集
public static void DisplayDefiningAssembly(this object obj)
{
Console.WriteLine("{0} lives here : =>> {1} \n", obj.GetType().Name, Assembly.GetAssembly(obj.GetType()).GetName().Name);
}
//本方法允许任何整型返回倒置的副本,如56将返回65;
public static int ReverseDigits(this int i)
{
//把int 翻译为string 然后获取所有字符
char[] digits = i.ToString().ToCharArray();
//反转数组中的项
Array.Reverse(digits);
//放回string
string newDigits = new string(digits);
//最后以int返回修改后的字符串
return int.Parse(newDigits);
}
}
static void Main(string[] args)
{
int i = 0;
i.DisplayDefiningAssembly();
System.Data.DataSet ds = new System.Data.DataSet();
ds.DisplayDefiningAssembly();
Console.ReadKey();
}
}
}