.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
    }
}
相关推荐
学以智用3 天前
C# Console App(控制台应用)模板详解
.net
宝桥南山4 天前
.NET 11 - 尝试一下Minimal API中的异步验证新特性
microsoft·微软·c#·asp.net·.net·.netcore
无风听海4 天前
深入理解.NET中的 Lazy<T>
服务器·php·.net
海盗12344 天前
微软技术日报 2026-10-14:十月补丁 1411 个漏洞,.NET 11 交出 RC2
人工智能·microsoft·机器人·aigc·.net
学以智用4 天前
.NET WinForms / WPF / Blazor 模板详解
.net
黄一一9112434 天前
吾爱大佬开发,离线可用!PDF文件处理工具,本地网页版文件-浏览器里就能搞定,所有操作系统可用
windows·安全·阿里云·pdf·.net·开源软件
慧都小妮子5 天前
MSG 附件太占内存?Aspose.Email for .NET 26.9 延迟加载
c#·.net·aspose·内存优化·延迟加载·aspose.email·附件内存
学以智用5 天前
ASP.NET Core 项目模板详解:Web应用 / Web API / MVC / Razor Pages
.net