c# ref 的作用

Posted Simple Programmer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# ref 的作用相关的知识,希望对你有一定的参考价值。

Usage of ref keyword in C# 

When we pass a value type variable as a parameter, then it passes its value as a parameter i.e. making a copy of the data. Making any changes inside the method in which it has been passed as a parameter will not affect the variable accessed outside the method. Because it is passed as a value and whatever the changes will be made inside the local method will be done on a copy of that variable.

If we need to change the value type variable from inside the method in which it has been passed as parameter, then you can pass this value type variable as the reference, using the ‘ref’ keyword. In this case, the reference of value type will be passed as a parameter rather than value of the variable

以上是关于c# ref 的作用的主要内容,如果未能解决你的问题,请参考以下文章

C#:关键字out和ref之间的区别

C#中关键字ref和out的区别

C#中的const形参

vue中ref($refs)用法和作用

在 React 样式组件上使用 'ref' 不起作用

ref 的作用