Unity_C# from where select 的用法

首先要引入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 list = new List(result);
 
        list.Sort();
 
        for (int i = 0; i < list.Count; i++) {
            print(list[i]);
        }
输出结果.png

以上from的用法其实类似for的用法

  for (int i = 0; i < result.Length; i++) {
         if (result[i] >= 5 && result[i] < 100) {
              //TODO
         }
  }

你可能感兴趣的:(Unity_C# from where select 的用法)