How can we get SBJSON connectionDidFinishLoading method inside array data in another class?

Problem in working with object array in c#. I have written the code below, please explain me.?

  • here when the compiler reaches the first method (s[i].get) inside for loop main function, it shows runtime error saying that object instance not defined properly, please explain me.. class super { public string name; public int roll; public int[] m = new int[5]; } class sub1 : super { public void get() { Console.WriteLine("\n\n\tName : "); name = Console.ReadLine(); Console.WriteLine("\n\n\tRoll : "); roll = int.Parse(Console.ReadLine()); Console.WriteLine("\n\n\tEnter marks : "); for (int i = 0; i < 3; i++) { m[i]=int.Parse(Console.ReadLine()); } } } class sub2 : sub1 { public void show() { Console.WriteLine("\n\n\tName : "+name); Console.WriteLine("\n\n\tRoll : "+roll); Console.WriteLine("\n\n"); for (int i = 0; i < 3; i++) { Console.WriteLine("\tm[{0}] : {1}\n\t", i, m[i]); } } } namespace MultilevelInheritance { class Program { static void Main(string[] args) { sub2[] s = new sub2[10]; Console.WriteLine("\n\n\tenter the no. of records : "); int n = int.Parse(Console.ReadLine()); Console.WriteLine("\n\n\tReading data : "); for (int i = 0; i < n; i++) { s[i].get(); } Console.WriteLine("\n\n\tDisplaying data : "); for (int i = 0; i < n; i++) { s[i].show(); } Console.Read(); } } }

  • Answer:

    When you do sub2[] s = new sub2[10]; you are declaring an array that can hold 10 sub2 objects, but it does NOT create the individual objects. You would first need to loop through the array and create each object.

rahul at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.