just to add also if you can avoid using ref and out i would do so, id suggest creating a new object that can hold the multiple values required
Main Topics
Browse All TopicsHi,
I am studying the parameter types.
I know the differences among different types(value, ref , out, and param type) and the differences among them.
However, when do we use these different types in a real world?
I mean I don't know when to use out parameter, when to use out parameter, etc..
For example, I know 'out' parameter doesn't need to be initialized before it's called, but I want to know the real world scenario that we might use.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
value is a keyword which holds the value of a parameter in the set accessor. This is the only place it exists and the only way to retrieve the value to set.
ref is useful when a method can modify one or more values and you don't know how it will be modified. For example, if you have to draw a list of items with variable heights in a self drawed list, you may have a "top" ref param which defines the top of the line to draw when calling the method which draws the line. In this method, you use this value to know where you start to draw and then you increment the value according to the height of the drawed line so that the next line is drawed just next to the previous one.
As showed in gspiteri's example, out is usefull when you need to test a result in order to know if the result is correct. It's the easy way to return multiple values and it should only be used in such simple cases or when you need performances (allows you not to have to instanciate a class which holds result values). Another difference with ref is that the out parameter MUST be set in the method.
params is usefull for method which accepts many parameters of the same type but you don't know how many. It is exactly the same thing as if you were instanciating an array and passing it as a parameters but allows you to keep a more elegant code especially when you have only one value in your array.
Business Accounts
Answer for Membership
by: gspiteriPosted on 2009-09-02 at 18:51:38ID: 25247284
With regards to a real world example for the out parameter it would be used when you want to return more then one value from a method.
Good example of this would be int.TryParse(string s , out p) the following method returns a bool value as well as a int from the output so you can use it like this:
Select allOpen in new window