I am new to c# and just practicing with object arrays. tried to display the elements of the array using loop but this code didn't display anything. Please help
using System;
using System.Text;
namespace pra
{
class program
{
public static void Main(string[] args)
{
person[] person1 = new person[2];
person1[0] = new person("Mike");
person1[1] = new person("John");
for (int i =0; i < person1.Length; i++)
{
Console.WriteLine("{0}",person1[i].Name);
}
}
}
class person
{
string name;
public string Name { get; set; }
public person(string name)
{
this.name = name;
}
}
}
personclass has a private membernamewhich you set in the constructor and a public auto-implemented propertyNamewhich you don't set - and you try to print the property which is not set