using System;
using System.Text;
using System.Reflection;
using System.Runtime.CompilerServices;
public static class MyExtensions
{
public static void DisplayDefiningAssembly(this object obj)
{
Console.WriteLine(obj.GetType().Name);
Console.WriteLine(Assembly.GetAssembly(obj.GetType()));
}
public static int ReverseDigits(this int i)
{
char[] digits = i.ToString().ToCharArray();
Array.Reverse(digits);
string newDigits = new string(digits);
return int.Parse(newDigits);
}
}
class Program
{
static void Main(string[] args)
{
int myInt = 987;
myInt.DisplayDefiningAssembly();
Console.WriteLine("{0} is reversed to {1}", myInt, myInt.ReverseDigits());
Console.ReadLine();
}
}
|