• 1397/03/10

خطا :

سلام

کدم اجرا  نمیشه :(((((

میگه  System.NullReferenceException: 'Object reference not set to an instance of an object.'

 

  Console.WriteLine("Please Enter number : ");
            int i = Convert.ToInt32(Console.ReadLine());
            ExampleClass[] examplearr = new ExampleClass[i];
            for (int j=0; j<i; j++)
            {
                Console.WriteLine("pleas Enter person 1 name : ");
                string ii = Console.ReadLine();
                examplearr[j].name = ii;
                Console.WriteLine("pleas Enter person 1 family : ");
                string bb = Console.ReadLine();
                examplearr[j].fmily = bb;
                Console.WriteLine("pleas Enter person 1 age : ");
                int gg = Convert.ToInt32(Console.ReadLine());
                examplearr[j].age = gg;
            }
            foreach(ExampleClass p in examplearr)
            {
                Console.WriteLine($"Name : {p.name} Family : { p.fmily} Age : { p.age}" );
            }
            Console.ReadKey();
  • 1397/03/10
  • ساعت 12:48

کدام خط ارور میده ؟


  • 1397/03/10
  • ساعت 12:56

examplearr[j].name=ii;


  • 1397/03/10
  • ساعت 13:51
 Console.WriteLine("Please Enter number : ");
            int i = Convert.ToInt32(Console.ReadLine());
            ExampleClass[] examplearr = new ExampleClass[i];
            for (int j=0; j<i; j++)
            {
                ExampleClass ec=new ExampleClass();
                Console.WriteLine("pleas Enter person 1 name : ");
                string ii = Console.ReadLine();
                ec.name = ii;
                Console.WriteLine("pleas Enter person 1 family : ");
                string bb = Console.ReadLine();
                ec.fmily = bb;
                Console.WriteLine("pleas Enter person 1 age : ");
                int gg = Convert.ToInt32(Console.ReadLine());
                ec.age = gg;
                examplearr[j]=ec;
            }
            foreach(ExampleClass p in examplearr)
            {
                Console.WriteLine($"Name : {p.name} Family : { p.fmily} Age : { p.age}" );
            }
            Console.ReadKey();

 


  • 1397/03/10
  • ساعت 14:02

ممنون


logo-enamadlogo-samandehi