- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between ref and out in C#
In this post, we will understand the difference between ‘ref’ and ‘out’ in C#.
Ref keyword
Before passing the parameters to ‘ref’, they need to be initialized.
It is not necessary to initialize the value of the parameter before it returns to the calling method.
The data can pass in two directions when the ‘ref’ keyword is used.
It is useful when the called method needs to change the value of the parameter that is passed.
Out keyword
It is not required to initialize parameters before it is passed to ‘out’.
It is required to initialize the value of a parameter before it is returned to the calling method.
Declaration of parameter using the ‘out’ keyword is helpful when a method needs to return multiple values.
When ‘out’ keyword is used, the data is passed in one direction only.