Working with objects in array-need help
Hi,
im doing very simple app and i wanna create array of sudents(std) and each std has array(3) grades-grade is a class as well.So each std has array of grades.Each grade has name and stdGrade.So each std has arrray of grade objects.Im trying to init std:
GradeClass[] stdGradeArr = new GradeClass[3];
Console.WriteLine("Std Grade for Math");
stdGradeArr [0].StdGrade = int.Parse (Console.ReadLine());
and i get error:obj ref not set to an instance of obj...
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

patrickRank #4,458 · 342 reputationPosted Sep 17, 2009, 10:32 AM EDT
Roei BarRank #1,271 · 1.4K reputationPosted Sep 17, 2009, 11:21 AM EDT
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication3 { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Student std = new Student(); std.Grades = new Grade[3]; Console.WriteLine("Std Grade for Math"); string _grade = Console.ReadLine(); std.Grades[0] = new Grade(); std.Grades[0].StdGrad = int.Parse(_grade); Console.WriteLine("Std Grade :" + std.Grades[0].StdGrad); Console.ReadLine(); } public class Student { public Grade[] Grades { get; set; } } public class Grade { public int StdGrad { get; set; } } } }