现在的位置: 首页 > 综合 > 正文

C# 数组最大值

2012年12月21日 ⁄ 综合 ⁄ 共 405字 ⁄ 字号 评论关闭
//下面是整个完整代码
using System;
using System.Collections.Generic;
using System.Text;

namespace ArrayMaxValue74
{
    class Program
    {
        public static int maxValue(int[] s)
        {
            int temp = s[0];
            for (int i = 0; i < s.Length; i++)
            {
                if (temp<=s[i])
                {
                    temp = s[i];
                }
            }
            return temp;
        }
        static void Main(string[] args)
        {
            int[] s={10,4,5,7,8,1};
            Console.WriteLine("the Max Value : {0}",maxValue(s));
            Console.ReadKey();
        }
    }
} 

 

 

用Linq直接查询int[] s = { 1, 5, 8, 9, 3 };

int xxx = (from mm in s select mm).Max();

【上篇】
【下篇】

抱歉!评论已关闭.