110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace My2
{
class Program
{
static void Main(string[] args)
{
struct Point :Ichanagep {
public int x, y;
public void Change(int x, int y)
{
this.x = x;
this.y = y;
}
public override string ToString()
{
return string.Format("({0},{1})",x,y );
}
}
interface Ichanagep {
void Change(int x,int y);
}
}
Point p = new Point();
p.x = p.y = 1;
Console.WriteLine(p );
p.Change(2,2);//这个就不说了
Console.WriteLine(p);
object o = p;//boxing
Console.WriteLine(o );
((Point)o).Change(3,3);//把o拆箱之后再change,所以,和p、o都没关系
Console.WriteLine(p.x );
Console.WriteLine(o );
((Ichanagep)p).Change(4,4);//把p装箱之后再change,所以,和p、o都没关系
Console.WriteLine(p );
((Ichanagep)o).Change(5,5);//把o强转之后再change,所以改变了o
Console.WriteLine(o);
namespace My2
{
class Program
{
static void Main(string[] args)
{
//Cat a = new Cat();
//a.eat();
//a.sleep();
//An n;
//n = a;
//n.sleep();
Point p = new Point();
p.x = p.y = 1;
Console.WriteLine(p );
p.Change(2,2);
Console.WriteLine(p);
object o = p;
Console.WriteLine(o );
((Point)o).Change(3,3);
Console.WriteLine(p.x );
Console.WriteLine(o );
((Ichanagep)p).Change(4,4);
Console.WriteLine(p );
((Ichanagep)o).Change(5,5);
Console.WriteLine(o);
Console.ReadKey();
}
}
//abstract class An {
// virtual public void sleep() { Console.WriteLine("animal is sleeping"); }
// // abstract public void eat();
//}
//class Cat : An ,Imp {
// public override void sleep()
// {
// Console.WriteLine("cat is sleeping");
// }
// public void eat() {
// Console.WriteLine("cat eat") ;
// }
//}
//interface Imp {
// void eat();
//}
struct Point :Ichanagep {
public int x, y;
public void Change(int x, int y)
{
this.x = x;
this.y = y;
}
public override string ToString()
{
return string.Format("({0},{1})",x,y );
}
}
interface Ichanagep {
void Change(int x,int y);
}
}