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<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
         }
  }

猜你喜欢

转载自blog.csdn.net/u012909508/article/details/84253201
今日推荐