Jac*_*wer -3 c# arrays oop object
我遇到了一些代码的问题,它覆盖了已声明的先前对象的名称.
我看不出修复.我试图多次修复它,我的同学找不到修复,我的老师也找不到.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OOP
{
class Student
{
private static string name;
private static DateTime DOB;
private static int ID;
private static double height;
private static string tutor;
public Student()
{
Console.Clear();
//Console.WriteLine("This is for student: " + (count + 1));
Console.WriteLine("Please enter the student's name");
name = Console.ReadLine();
//tryagain:
//try
//{
// Console.WriteLine("Please enter the Date of Birth");
// DOB = DateTime.Parse(Console.ReadLine());
// DOB = DOB.Date;
//}
//catch
//{
// Console.WriteLine("Please enter a valid date format");
// goto tryagain;
//}
//Console.WriteLine("Please enter the Student's ID");
//ID = int.Parse(Console.ReadLine());
//Console.WriteLine("Please enter the Student's Tutor");
//tutor = Console.ReadLine().ToUpper();
//Console.WriteLine("Please enter the Student's height(cm)");
//height = double.Parse(Console.ReadLine());
}
public void DispayData()
{
Console.WriteLine("Name- " + name);
Console.WriteLine("Date of Birth- " + DOB.Date);
Console.WriteLine("ID- " + ID);
Console.WriteLine("Tutor- " + tutor);
Console.WriteLine("Height- " + height);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the number of students");
int numStuds = int.Parse(Console.ReadLine());
Student[] studs = new Student[numStuds];
for (int i = 0; i < numStuds; i++)
{
studs[i] = new Student();
}
Console.Clear();
for (int f = 0; f < numStuds; f++)
{
display(studs[f]);
}
Console.ReadKey();
}
static void display(Student stud)
{
stud.DispayData();
Console.WriteLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)