现在的位置: 首页 > 综合 > 正文

string是一种特殊的引用类型,当给其赋值时会初始化一个新的string,即new String();

2012年12月08日 ⁄ 综合 ⁄ 共 1231字 ⁄ 字号 评论关闭

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TEST
{
    class Program
    {
        static void Main(string[] args)
        {

            //Obj obj = new Obj();
            //Obj obj2 = obj;
            //obj.Value = "1";
            //obj.ID = 1;
            //Console.WriteLine("obj.value:"+obj.Value +"  ID:"+obj.ID);
            //Console.WriteLine("obj2.value:" + obj2.Value + "  ID:" + obj2.ID);

            //obj.Value = "11";
            //obj.ID = 22;
            //Console.WriteLine("obj.value:" + obj.Value + "  ID:" + obj.ID);
            //Console.WriteLine("obj2.value:" + obj2.Value + "  ID:" + obj2.ID);

            //obj2.Value = "111";
            //obj2.ID = 222;
            //Console.WriteLine("obj.value:" + obj.Value + "  ID:" + obj.ID);
            //Console.WriteLine("obj2.value:" + obj2.Value + "  ID:" + obj2.ID);

            string str1;
            string str2;//string是一种特殊的引用类型,当给其赋值时会初始化一个新的string,即new String();

            str1 = "string1";
            str2 = str1;
            Console.WriteLine("str1:" + str1);
            Console.WriteLine("str2:" + str2);

            str2 = "string2";
            Console.WriteLine("str1:" + str1);
            Console.WriteLine("str2:" + str2);  

            Console.Read();
        }
    }

    class Obj
    {
        public string Value;
        public int ID;
    }
}

抱歉!评论已关闭.