The difference between C# key words 'ref ' and 'out'

In C# all parameters must be initialized before they can be passed to an method, and are passed by value. for reference type, the reference value is copied, and for value type , the value is copied.

If you want to persist the changes that the called mehtod made for the value type, you can use the key word 'ref' and 'out' which C# provided to force value parameters to be passed by reference. the different point about these two key words is that when you use 'ref' key word, you need to initialize the parameter before it is passed to method as usual, but for 'out' you don't need do that.

你可能感兴趣的:(C#)