建立乙個eocperson類,重寫nsobject協議中的-(bool)isequal:(id)object和-(nsuinteger)hash方法,方法的具體實現如下
eocperson.h
eocperson.m#import
@inte***ce
eocperson : nsobject
@property(nonatomic,copy) nsstring *firstname;
@property(nonatomic,copy) nsstring *lastname;
@property(nonatomic,assign) nsuinteger age;
@end
複習#import "eocperson.h"
@implementation
eocperson
-(bool)isequal:(id)object
if (![_lastname isequaltostring:otherperson.lastname])
if (_age != otherperson.age)
return
yes;
}-(nsuinteger)hash
@end
^按位異或:
複習一下按位異或
把數字轉化為二進位制:1^2 = 3
2^3 = 1
3^4= 7
...
按位異或操作解析:1 = 001
2 = 010
3 = 011
4 = 100
1^2 = 001
010------
011=3
2^3 = 010
011------
001=1
3^4 = 011
100------
111=7
Java中比較兩個物件是否相同
class person extends object 判斷是否是同齡人。書寫 順序 1 2 3 4 public boolean equals object obj public boolean compare person p class dog 定義乙個異常語句 public class ob...
js中比較兩個物件是否相同
js中,很輕易就可以比較2個普通字串 數字是否相同,但是,如何比較2個物件是否相同呢?在此我便給出較為簡單的方法,如下 比較2個物件是否相同 function isobjequal o1,o2 for var i 0,max props1.length i max i return true var...
比較兩個物件是否相等
using system using system.collections.generic using system.text using system.reflection namespace objectcompare public int age static class program 測試...