using system;namespace Conversion_Example{ class Program { static void Main(string[] args) { Teacher t = new Teacher(); Human h = t ; //把T这个变量所存的地址赋给了H /*当你拿一个引用变量去访问它所引用着的实例的成员的时候,只能访问到变量的类型所具有的成员,而不是这个变量所引用的实例的类型。所以H这个变量只有eat和think,没有teach, h.teach根本不存在*/ } } class Animal { public void Eat() { console.writeline("Eating....."); } } class Huamn:Animal { public void Think() { console.writeline("Who i am....."); } } class Teacher:Human { public void Teach() { console.writeline("i teach programming...."); } }}
例子:
double x = system.Convert.ToDouble(Text1);
double y = system.Convert.ToDouble(Text2);
double result = x+y;
this.Text3 = Convert.ToString(result);//或者result.ToString();
using system;namespace Conversion_Example{ class Program { static void Main(string[] args) { Stone stone = new Stone(); stone.age = 5000; Monkey wukongsun = (Monkey) stone; Console.Writeling(wukongsun.age); } } class Stone { public int age(); public static explicit operator Monkey(Stone stone) { Monkey m = new Monkey(); m.age = stone.age/500; return m; } } class Monkey { public int age; }}
"is"、"as"、"?:"、lambda