What is ref parameter?What is Out parameter?What's the difference between these two?

Showing Answers 1 - 3 of 3 Answers

Sachin

  • Aug 6th, 2007
 

Ref Parameter: Used to pass a parameter as a reference so that the function called will set the value. This could be used to return more than 1 value by a function.
e.g.

 public int AddMuliply( int a , int b, ref int c)
 {
  c = a*b;
  return ( a+b);
 }
 
The above function, returns the addition of two numbers as well as computes the multiplication result and passes to the calling function.
Out Parameter: Used to pass values from the aspx Code-behind to the aspx page.


Correct me if I am wrong.

  Was this answer useful?  Yes

Sachin

  • Aug 6th, 2007
 

Oops...

The difference is that for a ref parameter, you have to assign a value before you call the function, while for OUT parameter, you dont have to assign a value, the calling function assumes that the called function would assign some value.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.