Adding string items to a list of type Person C#
- by user1862808
Im makeing a simple registration application and I have an assignment to learn more about lists. I have an assignment that says that i am to create a class called Persons and in that class set the values from the text fields in variables and add this to a list of type Person.
So far:
in the Person class:
string strSocialSecurityNumber = string.Empty;//---( This will not be used now.)
string strFirstName = string.Empty;
string strLastName = string.Empty;
string strFullName = string.Empty;
string strAge = string.Empty;
string strAll = string.Empty;
int intAge = 0;
List<Person> lstPerson = new List<Person>();
public void SetValues(string FirstName, string LastName, int Age)
{
strFirstName = FirstName;
strLastName = LastName;
strFullName = strFirstName + " " + strLastName;
intAge = Age;
strAge = Convert.ToString(intAge);
strAll = strAge + " " + strFullName;
}
public List<Person> Person()
{
lstPerson.Add(strAll);
return lstPerson;
}
Error message:
"can not convert from string to Person"
The assignment says that the list is to be of the type Person so i am suppose to add strings to it and ive looked how to do this but I dont know how. I have seen that there are options like "ConvertAll" But im not sure if I am allowed to use it since the list should be of type Person.
Thank you!