(60)C#里判断引用相等的方法
在C#的开发里,经常会遇到判断两个对象是否相等的问题。如果是普通的值类型,就可以直接判断,使用等号即可,但是对于引用类型,直接判断就不一定行了。另外对于引用类型来说,可以有更加方便的办法来判断,比如两个引用类型的地址一样,那么这两个类型是一样的。
可以简单地使用函数System.Object.ReferenceEquals()来实现,用例子演示如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp43
{
class Program
{
public int Num { get; set; }
public string Str { get; set; }
static void Main(string[] args)
{
Program a = new Program() { Num = 1, Str = "Hi" };
Program b = new Program() { Num = 1, Str &


