e.g.
public var SomeMethod()
{
return "hello";
}
error:
The contextual keyword var may only appear within a local variable declaration
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
C# only supports type inference for local variables. It doesn’t support it for the return type of a non-anonymous function. This is a design decision. It’s possible that they change it in the future. Languages like F# do in fact support return type inference so there’s no inherent impossibility involved here. Of course, sometimes, the inferred return type may be ambiguous and requires further clarification in the languages that support it: