【发布时间】:2011-07-30 12:11:45
【问题描述】:
c#/.net中是否需要多个返回参数?
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 对象的属性。
标签: c# .net language-design