我想從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不存在的路線。 –