zoukankan      html  css  js  c++  java
  • ==与Equals

                //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  
    *****************




  • 相关阅读:
    iOS button总结
    蓝鸥 UI 考试 绝密
    iOS UI 21 消息通知
    iOS UI 21 单例中的线程
    iOS UI 21 线程
    iOS UI 21 动画
    iOS UI 20 音乐播放器
    深入Objective-C的动态特性
    符合iOS系统兼容性需求的方法
    IOS用NSLog做 debug调试
  • 原文地址:https://www.cnblogs.com/perfect/p/1207194.html
Copyright © 2011-2022 走看看