[读书]看看你有没有忽视
今天利用一点休息时间,随便翻了翻桌子上摆的一大摞书,看到了一小段代码,你也试试。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DotNetFramework
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
point.x = point.y = 1;
Console.WriteLine(point);
point.Change(2, 2);
Console.WriteLine(point);
object o = point;
Console.WriteLine(o);
((Point)o).Change(3, 3);
Console.WriteLine(o);
((IChangeBoxedPoint)point).Change(4, 4);
Console.WriteLine(point);
((IChangeBoxedPoint)o).Change(5, 5);
Console.WriteLine(o);
Console.Read();
}
interface IChangeBoxedPoint
{
void Change(Int32 x, Int32 y);
}
struct Point : IChangeBoxedPoint
{
public Int32 x;
public Int32 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);
}
}
}
}
写出程序运行结果。using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DotNetFramework
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
point.x = point.y = 1;
Console.WriteLine(point);
point.Change(2, 2);
Console.WriteLine(point);
object o = point;
Console.WriteLine(o);
((Point)o).Change(3, 3);
Console.WriteLine(o);
((IChangeBoxedPoint)point).Change(4, 4);
Console.WriteLine(point);
((IChangeBoxedPoint)o).Change(5, 5);
Console.WriteLine(o);
Console.Read();
}
interface IChangeBoxedPoint
{
void Change(Int32 x, Int32 y);
}
struct Point : IChangeBoxedPoint
{
public Int32 x;
public Int32 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);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DotNetFramework
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
point.x = point.y = 1;
// 显示(1,1)
Console.WriteLine(point);
point.Change(2, 2);
// 显示(2,2)
Console.WriteLine(point);
object o = point;
// 显示(2,2)
Console.WriteLine(o);
// 在堆栈上改变临时的point
((Point)o).Change(3, 3);
// 显示(2,2)
Console.WriteLine(o);
// 对point执行装箱,然后改变以装箱对象,最后将之丢弃
((IChangeBoxedPoint)point).Change(4, 4);
// 显示(2,2)
Console.WriteLine(point);
// 改变以装箱对象,并显示其内容
((IChangeBoxedPoint)o).Change(5, 5);
// 显示(5,5)
Console.WriteLine(o);
Console.Read();
}
interface IChangeBoxedPoint
{
void Change(Int32 x, Int32 y);
}
struct Point : IChangeBoxedPoint
{
public Int32 x;
public Int32 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);
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DotNetFramework
{
class Program
{
static void Main(string[] args)
{
Point point = new Point();
point.x = point.y = 1;
// 显示(1,1)
Console.WriteLine(point);
point.Change(2, 2);
// 显示(2,2)
Console.WriteLine(point);
object o = point;
// 显示(2,2)
Console.WriteLine(o);
// 在堆栈上改变临时的point
((Point)o).Change(3, 3);
// 显示(2,2)
Console.WriteLine(o);
// 对point执行装箱,然后改变以装箱对象,最后将之丢弃
((IChangeBoxedPoint)point).Change(4, 4);
// 显示(2,2)
Console.WriteLine(point);
// 改变以装箱对象,并显示其内容
((IChangeBoxedPoint)o).Change(5, 5);
// 显示(5,5)
Console.WriteLine(o);
Console.Read();
}
interface IChangeBoxedPoint
{
void Change(Int32 x, Int32 y);
}
struct Point : IChangeBoxedPoint
{
public Int32 x;
public Int32 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);
}
}
}
}