Out parameter and normal parameter difference?
What is the difference between Out parameter and a normal parameter in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Jun 27, 2015, 2:33 AM
Jaipal ReddyPosted Jun 27, 2015, 1:51 AM
If you want to pass a variable as out parameter you don’t need to initialize it before you pass it as out parameter to method. Out keyword also will pass parameter as a reference but here out parameter must be initialized in called method before it return value to calling method.
Declaration of Out Parameter
Generally we will use out parameters like as shown below
int i,j; // No need to initialize variable
Outsample(out i, out j);
If you observe above code first we declared variable and we it pass a out parameter to Outsample method without initialize the values to variables
Upendra Pratap ShahiPosted Jun 26, 2015, 7:54 AM
out (Output) Parameter
Output parameter is used to pass the result back to the calling function. ‘out’ keyword is used to declare the parameter as an Output parameter. Similar to a reference parameter, an output parameter does not create a new storage location. Instead, it becomes an alias to the parameter in the calling method.
Example of out Parameter
In the above program, x is declared as an out parameter in calling function and as you can see, x has not been initialized. When Square function terminates, the value of q will be copied to the output parameter x.
Rajeesh MenothPosted Jun 26, 2015, 6:13 AM
PrathapPosted Jun 26, 2015, 6:11 AM
Vignesh ManiPosted Jun 26, 2015, 5:59 AM
Rajeesh MenothPosted Jun 26, 2015, 5:50 AM