問題:
Someone asked me the other day when they should use the parameter keyword out
instead of ref
.前幾天有人問我什麼時候應該使用參數關鍵字out
而不是ref
。 While I (I think) understand the difference between the ref
and out
keywords (that has been asked before ) and the best explanation seems to be that ref
== in
and out
, what are some (hypothetical or code) examples where I should always use out
and not ref
.雖然我(我認爲)理解ref
和out
關鍵字( 之前已經問過)之間的區別,並且最好的解釋似乎是ref
== in
和out
,但我應該始終使用哪些(假設或代碼)示例使用out
而不是ref
。
Since ref
is more general, why do you ever want to use out
?既然ref
更通用,你爲什麼要使用out
? Is it just syntactic sugar?它只是語法糖嗎?
解決方案:
參考一: https://stackoom.com/question/6Mbk參考二: When to use in vs ref vs out