开发者

ref vs out in C# [duplicate]

开发者 https://www.devze.com 2023-01-24 23:52 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Difference between ref and out parameters in .NET
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Difference between ref and out parameters in .NET

When to use ref and when to use out ? What is diff开发者_StackOverflow中文版erence between the both ? How and where they are used ?

Please share an example showing difference between the both ref and out .

  • Thanks.


To my understanding:

ref means passing a variable by reference, which means you pass a pointer to that variable and it will retain modifications after leaving the function.

out means basically the same, except that the variable must be assigned before the function is exited, pretty much like return statements must be met before the function reaches completion.


I would start here. Jon does a good job explaining it all:

http://www.yoda.arachsys.com/csharp/parameters.html


There's any number of examples online.

A quick Google search found this: http://www.c-sharpcorner.com/UploadFile/mahesh/out_and_ref11112005002102AM/out_and_ref.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消