Which of the following is/are correct about OUT parameter?
-
Any changes made to the parameter will be reflected in the variable.
-
The out parameters is used to return values in the same variables, that you pass an an argument of a method
-
A variable to be sent as OUT parameter must be initialized
-
1 & 2
-
2 & 3
-
1 & 3
In C#, OUT parameters allow methods to return values through the same variables passed as arguments. Any changes to the parameter are reflected in the calling variable, and importantly, variables passed as OUT do NOT need to be initialized before being passed (unlike 'ref' parameters).
An out parameter in C#/.NET is passed by reference specifically so the called method can assign a value that flows back into the caller's variable, meaning any change made inside the method is reflected in that same variable after the call returns — that's statements 1 and 2. Statement 3 is false because, unlike ref parameters, variables passed as out do not need to be initialized beforehand since the method is required to assign them before returning.