LINQ MAX()函数

LINQ MAX()函数 首页 / LinQ入门教程 / LINQ MAX()函数

LINQ中的Max()函数用于返回集合中的最大值。在Max()函数的帮助下,使用Max()函数可以很容易地从给定的数据源找到最大值。在另一种情况下,我们必须编写代码以从值列表中获取最大值。

下面是使用LINQ Max()函数从C#中的列表或集合中获取最大值的语法。

C#中的Linq Max()函数语法

int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int MaximumNum = a.Max();

After observing the above syntax, we are getting the maximum value from the "a" list using LINQ Max () function.

示例:在此示例中,我们使用Max()函数从C#中的数组值列表中获取最大值。

using System;
using System.Collections.Generic;
using System. Linq;
using System. Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
//Create an array named 'a' type of int having the values 1 t 9
            int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            Console.WriteLine("The Maximum value in the array is:");
/*Max() function is applied on the array to 
find the maximum value from the arra*/
            int maximumNum = a.Max();

            Console.WriteLine("The maximum Number is {0}", maximumNum);

            Console.ReadLine();
        }
    }
}

输出

From the above example, it will show the integer array "a," and we are finding the maximum value from the given array using LINQ Max () function.

现在我们运行应用程序,它将显示列表中的最大值,如控制台窗口的输出中所示。

LINQ Max() Function




祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入剖析Kubernetes -〔张磊〕

白话法律42讲 -〔周甲徳〕

玩转webpack -〔程柳锋〕

Kafka核心技术与实战 -〔胡夕〕

SQL必知必会 -〔陈旸〕

Netty源码剖析与实战 -〔傅健〕

小马哥讲Spring AOP编程思想 -〔小马哥〕

React Hooks 核心原理与实战 -〔王沛〕

全链路压测实战30讲 -〔高楼〕

好记忆不如烂笔头。留下您的足迹吧 :)