Ref vs Out

Difference between a Ref and Out variable?

Ref and Out both signifies that value is to passed as a reference with major difference that out needs to be initialized with in the scope of the method other wise program will not be able to compile.


In order to make this able to compile we will have to assign num1 with value with in scope of OutExampleAdd10 method.



Conclusion


Once you compile it you will notice:
  • Purpose of ref variable is to carry the value in perform the function and carry the result back with it.
  • Purpose of out variable is not to carry the value in but carry the result back.




Comments

Popular posts from this blog

Azure - Manage Blob Storage - Part #7 - Add Metadata to an Existing Container using C#

Azure - Manage Blob Storage - Part #5 - Create Folder Structure and upload a file to folder using an Existing Container using C#

Algorithm - Breadth First Search(BFS) - Python(3)