using system;
using system.collections.generic;
using system.text;
namespace object.equals_方法
' and" +
" value is :", myvariable1.gettype(), myvariable1);
console.writeline("type of 'myvariable2' is '' and" +
" value is :", myvariable2.gettype(), myvariable2);
// compare 'myvariable1' instance with 'myvariable2' object.
if (myvariable1.equals(myvariable2))
console.writeline("/nstructures 'myvariable1' and " +
"'myvariable2' are equal");
else
console.writeline("/nstructures 'myvariable1' and " +
"'myvariable2' are not equal");
if(object.equals(myvariable1,myvariable2))
console.writeline("/nstructures 'myvariable1' and " +
"'myvariable2' are equal");
else
console.writeline("/nstructures 'myvariable1' and " +
"'myvariable2' are not equal");
console.writeline(myvariable1 == myvariable2);//但自定義的結構型別,不能用==進行比較,而自定義的類可以用==進行比較
if(referenceequals(myvariable1,myvariable1))
console.writeline("/nstructures 'myvariable1' and " +
"'myvariable2' are equal");
else
console.writeline("/nstructures 'myvariable1' and " +
"'myvariable2' are not equal");
console.readkey();}}
}
Object類的用法(一)
using system using system.collections.generic using system.text namespace object.referenceequals 方法 class a class b 對於類的例項的比較,這三種方法是作用是一樣的,都是比較引用 所有的類...
Object類方法簡介二
在學了object類前面的三個常用方法後,又遇到它的另外三個方法 clone finalize getclass 這三個方法不經常使用,但因為在學習過程遇到了,就簡單的對它們的使用做乙個總結。1.物件轉殖 clone 方法 protected object clone throws clonenot...
Object 類的比較
object 所有類的父類。所有物件都具備的內容不斷地抽取,就到了乙個頂層object類中。public class person public void setages int ages person int ages 既然父類中已經提供了對對像相等的比較,可以直接使用,如果比較內容不是所需要,可...