using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exercise_04
{
class Program
{
static void Main(string[] args)
{
string[] lines = System.IO.File.ReadAllLines(@"e:\hg.txt", Encoding.Default);
int maxScore = 0;
string maxName = "";
foreach(string line in lines)
{
string[] strs = line.Split('|');
string name = strs[0];
int score = Convert.ToInt32(strs[2]); //从数组中取出来后为string类型的所以要强制转换
if(score>maxScore)
{
maxScore = score;
maxName = name;
}
}
Console.WriteLine("成绩最高学生的姓名:{0}\n成绩:{1}", maxName, maxScore);
//或者
//Hashtable ht = new Hashtable();
//foreach (string l in lines)
//{
// string[] root = l.Split('|');
// if (ht.ContainsKey(root[3]))
// {
// string cj = ht[root[3]].ToString();
// if (int.Parse(cj) < int.Parse(root[2]))
// {
// ht[root[3]] = root[2];
// }
// }
// else
// {
// ht.Add(root[3], root[2]);
// }
//}
//foreach (var item in ht.Keys)
//{
// Console.WriteLine("年级为{0},最高成绩为{1}", item, ht[item]);
//};
Console.ReadKey();
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exercise_04
{
class Program
{
static void Main(string[] args)
{
string[] lines = System.IO.File.ReadAllLines(@"e:\hg.txt", Encoding.Default);
int maxScore = 0;
string maxName = "";
foreach(string line in lines)
{
string[] strs = line.Split('|');
string name = strs[0];
int score = Convert.ToInt32(strs[2]); //从数组中取出来后为string类型的所以要强制转换
if(score>maxScore)
{
maxScore = score;
maxName = name;
}
}
Console.WriteLine("成绩最高学生的姓名:{0}\n成绩:{1}", maxName, maxScore);
//或者
//Hashtable ht = new Hashtable();
//foreach (string l in lines)
//{
// string[] root = l.Split('|');
// if (ht.ContainsKey(root[3]))
// {
// string cj = ht[root[3]].ToString();
// if (int.Parse(cj) < int.Parse(root[2]))
// {
// ht[root[3]] = root[2];
// }
// }
// else
// {
// ht.Add(root[3], root[2]);
// }
//}
//foreach (var item in ht.Keys)
//{
// Console.WriteLine("年级为{0},最高成绩为{1}", item, ht[item]);
//};
Console.ReadKey();
}
}
}