0
私は本当にC#の初心者で、インターネットを検索しても時間を過ごしても解決できないこの問題に遭遇しました。スタックオブジェクトのGradesが常にヌルで、アプリケーションを実行するたびに「System.NullReferenceException」例外がスローされる理由を理解できません。私がGrades上でマウスの上を動かすと、「Field 'Student.Grades'は割り当てられず、常にデフォルト値nullになります」と表示されます。私はまた、 "{get; set;}"を使ってこのプロパティにアクセスすることはできません。だから誰も私になぜ教えることができますか?あなたはC#はスタックを設定できません
this.Grades =新しいスタックを追加することができ感謝!!!(初回が悪いの書式設定のため申し訳ありませんスタックオーバーフローの質問を)あなたのコンストラクタで
class Student : Person
{
public int studentID { get; set; }
public static int nextID;
public Stack<int> Grades;
public Student(string firstName, string lastName, DateTime birthDate,
string address1, string address2, string city, string state,
string zip, string country)
{
FirstName = firstName;
LastName = lastName;
BirthDate = birthDate;
Address1 = address1;
Address2 = address2;
City = city;
State = state;
Zip = zip;
Country = country;
//track the number of students enrolled
studentID = nextID;
nextID++;
}
}