Ref Vs Out Keyword
Ref vs Out Keyword in C#
Ref-
1)Ref parameter should have the same value.
2)Ref keyword is used to pass an argument as a reference
3) No Need to initialize out parameter before passing it.
Eg:=int a;
4) Out parameter must be initialized before returning.
Out -
1)Out parameters are not required to have value
2)Out keyword is also used to pass an argument like ref keyword
3)Must initialize Ref parameter else error.
Eg:=int b=5;
4) Ref parameter initialized not necessary.
When to use Out and Ref Parameter?
1)When you want to return more than one values from a method then you can use out and ref parameters.
Comments
Post a Comment