When a method is defined with an out parameter, why do I have to specify the out keyword when calling it. Its already there in the method definition, and the runtime should know that any parameter passed will be an out parameter.
It would make sense if the compiler will accept the argument with or without out keyword, with different semantic, but if you MUST add the keyword to make the code compile, whats the use? Shouldn’t the compiler handle it automatically?
Same for ref
May be because C# allows you to write overloads like this:
In this case compiles can’t understand that method with keywork
outshould be called if you don’t write this keyword when you call the method. And generally you should writeoutwhen method declared with this keyworrd.And of course when you write
outwhen you call method, you definitly know that this variale can be changed in method. It’s very readable.MSDN Article