Below is the interface and its implementation.
interface ICompanyService
{
Company GetCompany();
}
public class CompanyService : ICompanyService
{
public Company GetCompany()
{
//Do something
return new Compa开发者_如何学Gony();
}
}
Now if below "companyService" is the implementation of above ICompanyService, which one is better (A or B) and why?
var company = companyService.GetCompany(); //.....A
Company company = companyService.GetCompany(); //.....B
They are identical underneath.
A
is better because of readability. But that's subjective. Some people like lengthy lines.
Like Arnis says, they are identical underneath. Personally I'd prefer B in this case since you can't see the return type just by looking at the statement.
精彩评论