about ValueType

ValueType是抽象类:
ValueType overrides the virtual methods from Object with more appropriate (适当的)implementations(执行) for value types. See also Enum, which inherits from ValueType.

ValueType 重写从Object继承得到的虚方法,以使这些虚方法更好地配合ValueType。
Enum继承自ValueType。
————————————————————————————————
[]
[(true)]
[(.AutoDual)]
public class Object



Object的一个成员:
ToString()
--Returns a that represents the current .









public
virtual ToString ()
————————————————————————————————————
 1 None.gif using  System;
 2 None.gif using  System.Collections.Generic;
 3 None.gif using  System.Text;
 4 None.gif
 5 None.gif namespace  BoxedValueTypeField
 6 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 7InBlock.gif   
 8InBlock.gif    struct Point 
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
10InBlock.gif        public Int32 x, y;
11InBlock.gif        public void Change(Int32 x, Int32 y)
12ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
13InBlock.gif            this.x = x;
14InBlock.gif            this.y = y;
15ExpandedSubBlockEnd.gif        }

16InBlock.gif        public override string ToString()
17ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
18InBlock.gif            return String.Format("({0},{1})",x,y);
19ExpandedSubBlockEnd.gif        }

20ExpandedSubBlockEnd.gif    }

21InBlock.gif    class Program
22ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
23InBlock.gif        static void Main(string[] args)
24ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
25InBlock.gif            Point p = new Point();
26InBlock.gif            p.x = p.y = 1;
27InBlock.gif            Console.WriteLine(p);
28InBlock.gif
29InBlock.gif            p.Change(22);//调用了栈(Point)上的方法,改变了Point的字段
30InBlock.gif            Console.WriteLine(p);//output(2,2)
31InBlock.gif            //Console.WriteLine(Object value)
32InBlock.gif
33InBlock.gif            Object o = p;        //p被boxed,赋给o
34InBlock.gif            Console.WriteLine(o);//output (2,2)
35InBlock.gif            Console.WriteLine(p);//output (2,2)
36InBlock.gif            Console.WriteLine("---------");
37InBlock.gif            p.Change(55);
38InBlock.gif            Console.WriteLine(p);
39InBlock.gif            //但是这里o和p是两段内存中的两个对象,
40InBlock.gif            //所谓boxed,其实是一个移动的过程,
41InBlock.gif            //从栈(Point)上移动了一个p到堆(Program)上
42InBlock.gif            //其实是"地上有一瓶酒,装到箱子里,地上的这瓶酒到箱子里去了"
43InBlock.gif
44InBlock.gif
45InBlock.gif
46InBlock.gif            //把对象o临时Unboxed到一个临时栈上,将o转型为Point会对o执行Unboxed
47InBlock.gif            ((Point)o).Change(33);            
48InBlock.gif            //调用Change方法,该临时栈中的Point的字段的值为(3,3),已装箱Point对象却不会受影响
49InBlock.gif
50InBlock.gif            Console.WriteLine(o);
51InBlock.gif            //但o(在堆上)本身没有改变,所以这里输出(2,2)
52InBlock.gif            
53InBlock.gif            //这里的p是已经boxed的p,还是栈上的p,Jeffery说是已经boxed的
54InBlock.gif            Console.WriteLine(p);
55InBlock.gif            //p(在栈上)也没有改变,所以也输出(2,2),--前面已调用了p.Change(2,2)
56InBlock.gif            
57InBlock.gif            //Point tempP = ((Point)o).Change(3, 3); 要想得到这个(3,3)怎么办?
58InBlock.gif            //Console.WriteLine(tempP);
59InBlock.gif
60InBlock.gif            Console.Read();
61InBlock.gif
62ExpandedSubBlockEnd.gif        }

63ExpandedSubBlockEnd.gif    }

64ExpandedBlockEnd.gif}

65 None.gif

转载于:https://www.cnblogs.com/simhare/archive/2007/07/16/819251.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值