我想从SalesPerson
对象fullNameMethod
返回一个字符串到主程序,但这是行不通的。我究竟做错了什么?C#返回一个字符串方法
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);
}
}
什么不起作用? – CodeZombie
代码甚至没有编译。用'Console.WriteLine'命令行有语法错误。 – Oded
给我们提供错误信息。虽然它可能沿着x.fullNameMethod不存在的路线。 –