The Perfect Day

分享技术,编写未来

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
            //string类型的比较
            Console.WriteLine(a == b);
            Console.WriteLine(a.Equals(b));
            Console.WriteLine(
"*****************");

            
//引用类型(除string外)的比较
            object obj1 = a;
            
object obj2 = b;
            Console.WriteLine(obj1 
== obj2);
            Console.WriteLine(obj1.Equals(obj2));
            Console.WriteLine(
"*****************");

1、string a = "hello", b = "hello"; //不给b分配内存,只是将b指向"hello"(a和b指向的是同一个字符串"hello")
True
True
*****************
True
True
*****************

2、string a = "hello";
     string b = string.Copy(a); //创建了一个和a具有相同值的新的实例b
True
True
*****************
False 
True  
*****************

3、string a = new string(new char[] { 'h', 'e', 'l', 'l', '0' });
     string b = new string(new char[] { 'h', 'e', 'l', 'l', '0' });
True
True
*****************
False 
True  
*****************

4、string a = new string(new char[] { 'h', 'e', 'l', 'l', '0' });
     string b = "hello";
True 
True 
*****************
False 
True  
*****************




posted on 2008-05-26 01:13  StephenJu  阅读(508)  评论(0编辑  收藏  举报