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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vignesh ManiRank #98 · 22.1K reputationPosted Jun 26, 2015, 1:59 AM EDT
Prathap39 reputationPosted Jun 26, 2015, 2:11 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 26, 2015, 1:50 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 26, 2015, 2:13 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 26, 2015, 3:54 AM EDT
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.
Jaipal ReddyRank #588 · 4.1K reputationPosted Jun 26, 2015, 9:51 PM EDT
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
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Jun 26, 2015, 10:33 PM EDT