.NET from-where-select用法

直接上示例代码进行说明:

  1. from-where-select的用法:
cs 复制代码
int[] arr = {3, 4, 5, 6, 7, 8, 9};

int[] res = (from a in arr
                where a > 4 && a < 9
                select a).ToArray();

List<int> lst = new List<int>(res);
foreach (var item in lst) => Console.WriteLine($"item");
  1. 运行结果:
cs 复制代码
5
6
7
8
  1. 以上from-where-select用法可以for用法解读:
cs 复制代码
for (int i = 0; i < res.Length; i++)
{
    if (res[i] > 4 && res[i] < 9)
    {
        //TODO
    }
}
相关推荐
geovindu10 小时前
CSharp: Iterative Algorithms
开发语言·后端·算法·c#·.net·迭代算法
geovindu3 天前
CSharp: Flyweight Pattern
开发语言·后端·c#·.net·享元模式·结构型模式
驰骋工作流3 天前
请假流程:六款.NET工作流引擎实现方式对比
.net·ccflow·工作流引擎二开·.net工作流引擎对比
WarPigs3 天前
.NET项目app.Config笔记
c#·.net
海盗12344 天前
微软技术周报——2026-07-22
microsoft·c#·.net
海盗12344 天前
微软技术日报 ——2026-07-21
microsoft·c#·.net
半亩码田4 天前
【.NET新特性·第8篇】.NET 9 AI 构建基块:Microsoft.Extensions.AI
人工智能·microsoft·.net
Ctrl+Z侠4 天前
.NET WebApi Windows / Linux Docker 全链路压测与瓶颈定位 0 到 1 教程
linux·windows·.net
慧都小妮子4 天前
Aspose.CAD for .NET 26.6 更新发布
pdf·.net·3d渲染·cad·pdf导出·ifc编辑
夜莺悠吟5 天前
关于对 C# 中 ImplicitUsings,GlobalUsings 的讨论
c#·.net