这里面包含了隐式转换,byte a = 1; Int32 b = 1; b = a;//可以 a = b;//错误
我们直接在vs中,把光标放到Equals方法上面,按F12。 直接看一段里面的解释就知道Equals方法是比较什么的了。 // // 摘要: // Returns a value indicating whether this instance is equal to a specified // System.Int32 value. // // 参数: // obj: // An System.Int32 value to compare to this instance. // // 返回结果: // true if obj has the same value as this instance; otherwise, false. public bool Equals(int obj); // // 摘要: // Returns a value indicating whether this instance is equal to a specified // object. // // 参数: // obj: // An object to compare with this instance. // // 返回结果: // true if obj is an instance of System.Int32 and equals the value of this instance; // otherwise, false. public override bool Equals(object obj); 另外,你执行以下: Console.WriteLine(a.Equals((byte)b)); 看看结果是什么。
Int32 b = 1;
b = a;//可以
a = b;//错误
直接看一段里面的解释就知道Equals方法是比较什么的了。
//
// 摘要:
// Returns a value indicating whether this instance is equal to a specified
// System.Int32 value.
//
// 参数:
// obj:
// An System.Int32 value to compare to this instance.
//
// 返回结果:
// true if obj has the same value as this instance; otherwise, false.
public bool Equals(int obj);
//
// 摘要:
// Returns a value indicating whether this instance is equal to a specified
// object.
//
// 参数:
// obj:
// An object to compare with this instance.
//
// 返回结果:
// true if obj is an instance of System.Int32 and equals the value of this instance;
// otherwise, false.
public override bool Equals(object obj);
另外,你执行以下: Console.WriteLine(a.Equals((byte)b)); 看看结果是什么。
可能是clr做了一些动作吧。求解。
戻り値:
// obj がこのインスタンスと同じ値を保持している場合は true。それ以外の場合は false。
public bool Equals(byte obj);
// 戻り値:
// obj がこのインスタンスに等しい場合は true。それ以外の場合は false。
返回值的判定条件不同。(蛋疼,我是日文系统,顺道问下不改变操作系统语言的情况下,vs语言能变成英文么。)