今天又去把C#入门经典借来,准备认认真真的看一遍。

   C#基础部分由三点收获

   1.C#预定义类型中除了string和objiect外,其它的全是值类型。自定义类型为应用类型。

   2.

string s1="a string";
string s2=s1;
console.writeline(
"s1 is"+s1);
console.writeline(
"s2 is"+s2);
s1
="another string";
console.writeline(
"s1 is now"+s1);
console.writeline(
"s2 is now"+s2);

结果是:

s1 is a string

s1 is a string

s1 is now another string

s1 is a string

当用值"a string"初始化s1时,就在堆上分配了一个string对象。在初始化s2时,引用页指向这个对象,所以s2的值也是"a string"。但是要改变s1的值时,不会替换原来堆中的值,堆上会为新值分配一个新的对象。s2还是原来的对象,所以值不变。

3.

int[] integers = new int[32];
int[] copy = integers;

 

上面integers和copy是指向同一个数组,而不是重新创建一个新数组。所有数组都是值类型。
posted on 2009-11-07 19:42  му﹏餉袏赱  阅读(124)  评论(0编辑  收藏  举报