using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class hashtable
{
string name;
string schoolnumber;
static public int lenght;
public string Name
{
get { return name; }
set { name = value; }
}
public string Schoolnumer
{
get { return schoolnumber; }
set { schoolnumber = value; }
}
}
class Program
{
static void Main(string[] args)
{
hashtable[] student = new hashtable[100];
hashtable.lenght = 0;
char n = new char();
Console.Write("姓名:");
string name = Console.ReadLine();
Console.Write("学号:");
string number = Console.ReadLine();
student[hashtable.lenght] = new hashtable();
student[hashtable.lenght].Name = name;
student[hashtable.lenght].Schoolnumer = number;
hashtable.lenght++;
Console.Write("是否结束输入(Y/N):");
n = Convert.ToChar(Console.ReadLine());
while ((n != 'Y') && (n != 'y'))
{
Console.Write("姓名:");
name = Console.ReadLine();
Console.Write("学号:");
number = Console.ReadLine();
bool f = true;
for (int i = 0; i < hashtable.lenght; i++)
{
if (number == student[i].Schoolnumer)
{
Console.WriteLine("该学生的信息已经存在。");
f=false;
break;
}
}
if(f)
{
student[hashtable.lenght] = new hashtable();
student[hashtable.lenght].Name = name;
student[hashtable.lenght].Schoolnumer = number;
hashtable.lenght++;
}
Console.Write("是否结束输入(Y/N):");
n = Convert.ToChar(Console.ReadLine());
}
for (int i = 0; i < hashtable.lenght; i++)
{
int w = student[i].Schoolnumer.Length;
int m = (student[i].Schoolnumer.ToArray()[w-1]-'0');
if ((m % 2) != 0)
{
Console.WriteLine("姓名:{0}", student[i].Name);
Console.WriteLine("学号:{0}", student[i].Schoolnumer);
}
}
Console.ReadKey();
}
}
}
C#类数组
最新推荐文章于 2023-07-05 23:24:15 发布