Possible Duplicate:
Whats the difference between the 'ref' and 'out' keywords?
What is the difference between ref and out? I am confused about when to use ref and out. So please explain how to use ref and out, and in which situations.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You use Out when you pass an un-initialized parameter and the method will have to initialize and fill that parameter (you get a warning or even error otherwise).
bool IsUserValid(string username);
void IsUserValid(string username, out bool valid);
The declarations above are roughly the same. It’s easier to return the value, so in this case you will use the return type. But if your method also needs to return the birth date of the user you can’t return both parameters in the return, you have to use out parameters to return one of them (or void the method and return both as out).