Hello every one,
What i need to do is to make an array of my own class and then assign values to that array
I made an array and when i try to assign value it gave me an exception
Your support is highly appreciated.
static void Main(string[] args)
{
string Fname;
string Lname;
string Email;
int age;
Person [] Parray = new Person[3];
Person p1 = new Person();
for (int i = 0; i < 2; i++)
{
Console.WriteLine("Enter your first name ");
Parray[i].Fname1 = Console.ReadLine();
Console.WriteLine("Enter your last name ");
Parray[i].Lname1= Console.ReadLine();
//Console.WriteLine("Welcome Mr." + " ");
//Console.WriteLine("Enter your age ");
//Parray[i]= int.Parse ( Console.ReadLine());
}
}
}
}
The person class :-
class Person
{
string firstName;
string lastName;
int birthDate;
string email;
//public Person(string intifirst, string intilast, int intibirth, string intiemail)
//{
// firstName = intifirst;
// lastName = intilast;
// birthDate = intibirth;
// email = intiemail;
//}
//public Person(string intifirst, string intilast, int intibirth)
//{
// firstName = intifirst;
// lastName = intilast;
// birthDate = intibirth;
//}
//public Person(string intifirst, string intilast, string intiemail)
//{
// firstName = intifirst;
// lastName = intilast;
// email = intiemail;
//}
public string Fname1
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string Lname1
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
public int age
{
get
{
return birthDate;
}
set
{
birthDate = value;
}
}
public void show()
{
Console.WriteLine("your first name is " + firstName);
Console.WriteLine("your last name is " + lastName);
Console.WriteLine("your E-mail is " + email);
Console.WriteLine("your age" + birthDate);
}
}
}
`