c# equals和==的区别

简言之:

equals必须是类型和值都得相等

== 只要值相等

 

注意:

void Main()

{

    int a=10;

    short b=10;

    Console.WriteLine(a.Equals(b)); //True  (short会隐式转换为int)

    Console.WriteLine(b.Equals(a)); //False (int不会隐式转换为short)

} 

 

你可能感兴趣的:(equals)