C# ref 和 out 异同

ref and out

ref out
it is necessary the parameters should initialize before it pass to ref. it is not necessary to initialize parameters before pass to out.
It is not necessary to initialize the value of a parameter before returning to the calling method. It is necessary to initialize the value of a parameter before returning to the calling method.
The passing of value through ref parameter is useful when the called method also need to change the value of passed parameter. The declaring of parameter through out parameter is useful when a method return multiple values.
When ref keyword is used the data may pass in bi-directional. ref 主要用于双向的数据传递 When out keyword is used the data only passed in unidirectional. out主要用于单向的数据传递
posted @ 2019-09-24 14:22  YanyuWu  阅读(101)  评论(0编辑  收藏  举报