+ 5

What's the difference between ref and out in C# ?

C#

8th Feb 2020, 5:12 AM
Girly
Girly - avatar
3 odpowiedzi
+ 5
rel is used to state that the parameter passed may be modified by the method. in is used to state that the parameter passed cannot be modified by the method.  Out is used to state that the parameter passed must be modified by the method.
8th Feb 2020, 5:31 AM
SHADOW 🌀
SHADOW 🌀 - avatar
+ 3
ref is may be modified by method out is must be modified by method in is cannot be modified by the method.
8th Feb 2020, 5:23 AM
BroFar
BroFar - avatar
+ 2
Variables passed by `ref` specifier need to be initialized before they can be used e.g. passing them to a method. Variables passed by `out` specifier are not necessarily be initialized before they can be used e.g. passing them to a method. https://www.dotnettricks.com/learn/csharp/difference-between-ref-and-out-parameters
8th Feb 2020, 6:54 AM
Ipang