一 求整数数组里最大的整数和学生数组里分数最高的学生
二代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace CsharpConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//求整形数组里最大的整数
int[] num = {3,8,2,13,5,21};
int max = 0;
max = GetMaxInt(num);
System.Console.WriteLine("数组里最大的数是: "+max);
//求学生里分数最高的学生的名字
STUDENT[] stu = { new STUDENT(){ name="小明", score=98 }, new STUDENT(){ name="胖子", score=78 } ,new STUDENT(){name="大头" ,score = 88} };
STUDENT maxScoreStu = GetMaxStudent(stu);
System.Console.WriteLine("分数最高的学生是: "+maxScoreStu.name);
System.Console.ReadLine();
}
static public int GetMaxInt(int[] num)
{
int i = 0 ;
int max = num[0];
for (i = 0; i < num.Length; i++)
{
if (max < num[i])
{
max = num[i];
}
}
return max;
}
static public STUDENT GetMaxStudent(STUDENT[] stu )
{
int i = 0;
STUDENT max = stu[0];
for(i = 0 ; i< stu.Length ; i++)
{
if(max.score <stu[i].score)
{
max = stu[i];
}
}
return max;
}
}
class STUDENT
{
public string name { get; set; }
public int score { get; set; }
}
}