首先要引入using System.Linq;
int[] test = { 1, 24, 5, 87, 0 ,53,15,100,6};
int[] result = (
from val in test
where val >= 5 && val <100
select val).ToArray();
List<int> list = new List<int>(result);
list.Sort();
for (int i = 0; i < list.Count; i++) {
print(list[i]);
}
以上from的用法其实类似for的用法
for (int i = 0; i < result.Length; i++) {
if (result[i] >= 5 && result[i] < 100) {
//TODO
}
}