这是我以前做过的一个,你可以参考一下。利用k
do
{
//Console.Write("输入0结束,任意键继续");
//k = Console.ReadKey().KeyChar;
Console.Clear();
Console.WriteLine("*******************主菜单*******************");
Console.WriteLine("**************选择你要的服务:**************");
Console.WriteLine("****************1、输入信息*****************");
Console.WriteLine("****************2、浏览信息*****************");
Console.WriteLine("****************3、排序*********************");
Console.WriteLine("****************4、查询*********************");
Console.WriteLine("****************5、结束*********************");
int num = 0;
Console.Write("请输入您的选择:");
num = int.Parse(Console.ReadLine());
switch (num)
{
case 1:
{
Console.Clear();
for (int i = 1; i < m+1; i++)
{
Console.Write("请输入学生{0}的学号(姓名):",i);
iArray[i, 0] = Convert.ToString(Console.ReadLine());
for (int j = 1; j < n+1; j++)
{
//Console.WriteLine();
Console.Write("{0}的成绩:",iArray[0,j]);
iArray[i, j] = Convert.ToString(Console.ReadLine());
}
}
} break;
case 2:
{
Console.Clear();
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t",iArray[0,j]);
for (int i = 1; i < m + 1; i++)
{ Console.WriteLine();
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t", iArray[i, j]);
}
Console.WriteLine("\n按任意键回主菜单");
Console.ReadLine();
} break;
case 3:
{
Console.Clear();
int num3=0;
string temp,temp1;
int k3 = 1;
do
{
Console.Clear();
Console.WriteLine("选择排序的科目:");
for (int j = 1; j < n + 1; j++)
{
Console.WriteLine("{0}、按{1}", j, iArray[0, j]);
}
Console.WriteLine("{0}、返回主菜单", n + 1);
if (!int.TryParse(Console.ReadLine(), out num3))
return;
for (int m1 = 1; m1 < n + 1; m1++)
if (num3 == m1)
{
for (int i = 1; i < m; i++)
for (int n1 = i + 1; n1 < m + 1; n1++)
if (string.Compare(iArray[i, num3], iArray[n1, num3]) < 0)
{
temp = iArray[i, num3];
temp1=iArray[i,0];
iArray[i, num3] = iArray[n1, num3];
iArray[i,0]=iArray[n1,0];
iArray[n1, num3] = temp;
iArray[n1, 0] = temp1;
}
Console.Clear();
Console.Write("{0}\t", iArray[0, 0]);
Console.Write("{0}\t", iArray[0, num3]);
for (int i = 1; i < m + 1; i++)
{
Console.WriteLine();
Console.Write("{0}\t", iArray[i, 0]);
Console.Write("{0}",iArray[i,num3]);
}
Console.WriteLine("\n{0}最高分为{1},最低分为{2}",iArray[0,num3],iArray[1,num3],iArray[m,num3]);
Console.ReadLine();
}
else if (num3 == n + 1)
k3 = 0;
} while (k3 != 0);
} break;
case 4:
Console.Clear();
Console.Write("请输入要查找的学号(姓名):");
string x;
x = Console.ReadLine();
int pos = -1;
for (int i = 1; i < m+1; i++)
if (string.Equals(x,iArray[i, 0]))
{
pos = i;
Console.WriteLine("{0}在数组中位置为{1}", x, pos);
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t", iArray[0, j]);
Console.WriteLine();
for (int j = 0; j < n + 1; j++)
Console.Write("{0}\t", iArray[pos, j]);
}
if (pos == -1)
Console.WriteLine("{0}不存在于数组中", x);
Console.ReadLine();
break;
case 5:
k = 0;
break;
}
}
while (k!=0);