c#/ .net中是否需要多個返回參數?具有多個返回參數的C#方法
public string, string GetFirstNameAndLastName(int id)
{
var person = from p in People
where p.Id = id
select p;
return(p.FirstName, p.LastName);
}
用法:
public void Main(string[] args)
{
string firstName, lastName;
(firstName, lastName) = GetFirstNameAndLastName(1);
Console.WriteLine(firstName + ", " + lastName);
}
爲什麼你需要將firstName&lastName作爲單獨的值返回?它們不應該在Person實例中表示嗎? FirstName和LastName是Person對象的屬性。 – 2011-04-06 04:44:27