//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("*****************");
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
*****************