我有一个数组,说如何检查数组中的所有元素是否都是正整数?
int[] array = new int[] { 1, 5, 11, 5 };
我如何检查(以最简便而有效的),所有的元素都是正?如果至少有一个数字不是正整数,系统将以负面方式进行响应。
所需的输出:
如果所有的数字都是肯定的,那么它会显示 “一切积极” 其他 “错误”
我的投篮
int[] array = new int[] { 1, 5, 11, 5 };
var x = array.All(c => c >= '0' && c <= '9');
if (x == true) "Positive" else "Wrong";
'array.All(x => x> -1)'? – Patashu 2013-05-09 05:43:02
那么你应该检查使用'.Any'是否小于零 – V4Vendetta 2013-05-09 05:44:34