Adding string items to a list of type Person C#

Posted by user1862808 on Stack Overflow See other posts from Stack Overflow or by user1862808
Published on 2012-12-02T16:51:57Z Indexed on 2012/12/02 17:04 UTC
Read the original article Hit count: 228

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about c#

Related posts about homework