public class MyType { int _Value; public static MyType operator++(MyType a) { a._Value++; return a; } }
using System;namespace lianxi {
class myclass { public int x,y; public myclass() {} public myclass(int a,int b) { x = a; y = b; } public static myclass operator ++(myclass z) { z.x++; z.y++; return z; } } /// <summary> /// Class1 的摘要说明。 /// </summary> class Class1 {
{
int _Value; public static MyType operator++(MyType a)
{
a._Value++;
return a;
}
}
{
class myclass
{
public int x,y;
public myclass()
{}
public myclass(int a,int b)
{
x = a;
y = b;
}
public static myclass operator ++(myclass z)
{
z.x++;
z.y++;
return z;
}
}
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
myclass xxx = new myclass(1,1);
myclass yyy = xxx++;
Console.WriteLine("x={0},y={1}",yyy.x,yyy.y);
Console.WriteLine("x={0},y={1}",xxx.x,xxx.y);
}
}
}
------------------------输出结果------------------------
x=2,y=2
x=2,y=2
我的想法应该是输出:
x=1,y=1
x=2,y=2我该怎么做??????
这句话的意思是 yyy和xxx是同一个实例.就是说,你改变任一个值, 另一个也会变重载=操作才能解决这个问题.
myclass xxx= new myclass(1, 1);
myclass yyy= new myclass(1,1);yyy= xxx++ ==============> 这是=操作