标签:read 存在 c# write file string oid als 姓名
static void Main(string[] args)
{
Console.WriteLine("请输入要查询的学生姓名!");
string nameToQuery = Console.ReadLine();
using (Stream stream = File.OpenRead(@"D:\C#\vs2015\SearchScore\Score.txt"))
using (StreamReader reader = new StreamReader(stream))
{
string line;
bool isFound = false;
while ((line = reader.ReadLine()) != null)
{
string[] strs = line.Split(‘ ‘);
string name = strs[0];
string score = strs[1];
if (string.IsNullOrEmpty(nameToQuery))//输入为空,成绩全部输出
{
Console.WriteLine(name + "的成绩是" + score);
}
else
{
if (name == nameToQuery)
{
Console.WriteLine("成绩是" + score);
isFound = true;
}
}
}
if (!string.IsNullOrEmpty(nameToQuery) && !isFound)
{
Console.WriteLine(nameToQuery +"的成绩不存在!!!");
}
}
Console.ReadKey();
}
标签:read 存在 c# write file string oid als 姓名
原文地址:http://www.cnblogs.com/liulida/p/7163640.html