I just got this error when trying to use a function parameter for a return value.
I could only find answers to related issues but not this one.
Example:
void someNumber(int foo)
{
foo = 3;
}
int bar;
someNumber(bar);
What’s the problem here?
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.
As it turns out C# is a bit weird in this respect but better weird than C/C++. 🙂
If you pass a reference only for the output value you have to make that explicit in this way:
So while you still have an output parameter in the input parameter list (at least that’s what it is in my head) at least it is now blatantly obvious.
Note that it is now an error NOT to assign to foo in the body of someNumber. It’s kind of like an anti-const, which would obviously have been a much cooler keyword. 😉