I am trying to return a string from the SalesPerson object with fullNameMethod to the main program, but this isn’t working. What am I doing wrong?
class SalesPerson
{
string firstName, lastName;
public string FirstName { get { return firstName; } set { firstName = value; } }
public string LastName { get { return lastName; } set { lastName = value; } }
public SalesPerson(string fName, string lName)
{
firstName = fName;
lastName = lName;
}
public string fullNameMethod()
{
string x = firstName + " " + lastName;
return x;
}
}
class Program
{
static void Main(string[] args)
{
SalesPerson x = new SalesPerson("john", "Doe");
Console.WriteLine("{0}", x.fullNameMethod);
}
}
You’re currently trying to access a method like a property
It should be
Alternatively you could turn it into a property using