怎么证明string不是值类型

   public string testStatic()
        {
            
            string str = "test";

            int hashcode0 = str.GetHashCode();
            int hashcode1 = test(str);
            str += "oooo";
            int hashcode2 = str.GetHashCode();

            return string.Format(" hashcode0 :{0} </br> hashcode1 :{1} </br> hashcode2 :{2}  ", hashcode0, hashcode1, hashcode2);

        }
        public int test(string str)
        {
            return str.GetHashCode();
        }


其输出:
hashcode0 :-354185609 
hashcode1 :-354185609 
hashcode2 :-19413537
其中hashcode0和hashcode1是相等的,说明string 是引用同一个地址,而hashcode2是
str += "oooo";之后 ,说明这个str是一个新的址了,也就是说str是一个新的string对象。

posted @ 2016-02-17 17:52  Pello  阅读(180)  评论(0编辑  收藏  举报