2012-06-07 24 views
-3

我想有這樣的:需要這樣的東西大於或 - 等於

int x = arrayX.count; 
int y = arrayY.count; 

if (x >= y) { 
//do something 
} 

這可能嗎?

+0

取決於x和y –

+1

'int x = 5; int y = 5;如果(x> = y){//東西}'應該工作 – Almo

+2

沒有指定x和y的類型,這個問題不能回答 – scord

回答

1

是的,它應該工作,只要xy是原始值,如intfloat。 (它不適用於像NSNumber這樣的對象,您需要使用提供的方法之一從該對象獲取原始值)。

+0

當然,這就是爲什麼我說它會在原始價值觀上工作。 'intValue'和'floatValue'返回原語。 –

1

您也可以使用-compare:消息有許多類型的對象:

if ([[NSDate date] compare:self.targetDate] == NSOrderedAscending) { 
    ... // targetDate is in the future. 
} 
else if ([[NSDate date] compare:self.targetDate] == NSOrderedDescending) { 
    ... // targetDate is in the past. 
} 
else { // NSOrderedSame 
    ... // Dates are exactly the same. 
} 

示例代碼。不好的代碼。 :-)

相關問題