What's the difference between ref and out in C# ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 5

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

C#

8th Feb 2020, 5:12 AM
Girly
Girly - avatar
3 Respostas
+ 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