如何测试,看是否使用数量的Objective-C是范围? [英] How to test to see if number is in range using Objective-C?
问题描述
我有一个非常基本的问题。我想知道,如果这里是在Objective-C或C内置功能来帮我找,如果一个具体的数字是在一定范围内。我知道,这可能是简单的问题,但我仍然没有找到答案。在短期方面,想避免使用多个的if和其他S此测试。
NSLocationInRange(C,NSMakeRange(A,(B - A)))
这会返回一个布尔如果c深藏在a和b。但是a,b和c必须是无符号整型。这实在是不太好找。所以我想这是更好的对自己进行比较。
C> = A && C< = B
I have a very basic question. I would like to know if here is a built-in function in Objective-C or C to help me find if a specific number it's in a certain range. I know that this is probably easy question but still I didn't found an answer. On short terms, would like to avoid using multiple "if"s and "else"s for this test.
NSLocationInRange(c, NSMakeRange(a, (b - a)))
This returns a BOOL if c lies within a and b. However a,b and c must be unsigned int. And this is really not very good looking. So I guess it is far better to compare myself.
c >= a && c <= b
这篇关于如何测试,看是否使用数量的Objective-C是范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!