using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Program a = new Program();
Program b = new Program();
if (a.Equals(b))
{
Console.WriteLine("a=b");
}
Console.WriteLine("a:{0}", a.GetHashCode());
Console.WriteLine("b:{0}", b.GetHashCode());
Program c = a;
if (a.Equals(c))
{
Console.WriteLine("a=c");
}
String str1 = new String("Hello".ToCharArray());
String str2 = new String("Hello".ToCharArray());
if (str1.Equals(str2))
{
Console.WriteLine("str1=str2");
}
if (str1==str2)
{
Console.WriteLine("str1=str2");
}
Console.WriteLine("str1:{0}", str1.GetHashCode());
Console.WriteLine("str2:{0}", str2.GetHashCode());
if (Object.ReferenceEquals(str1,str2))
{
Console.WriteLine("Object.ReferenceEquals(str1,str2)");
}
else
{
Console.WriteLine("Object.Reference not Equals(str1,str2)");
} }
}
}
/*
a:46104728
b:12289376
a=c
str1=str2
str1=str2
str1:-694847
str2:-694847
Object.Reference not Equals(str1,str2)
请按任意键继续. . .
*/
if (Object.ReferenceEquals(str1,str2))
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
ES6的Object.fromEntries()和Object.hasOwn()
Object.fromEntries()方法是Object.entries()的逆操作,用于将一个键值对数组转为对象。
键值对 Object.hasOwn() Object.fromEntries -
object.ReferenceEquals 方法
转自 object.ReferenceEquals 方法_夜晚回家的博客-CSDN博客为了了解 C# uild
c# linq 开发语言 ReferenceEquals 字符串常量