What's so bad about ref parameters?

后端 未结 12 600
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 09:49

I\'m faced with a situation that I think can only be solved by using a ref parameter. However, this will mean changing a method to always accept a ref parameter when I only

12条回答
  •  醉梦人生
    2021-01-11 10:10

    The most common use I've seen for ref parameters is as a way of returning multiple values. If that's the case, you should consider creating a class or struct that returns all the values as one object. If you still want to use a ref but want to make it optional, add a function overload.

提交回复
热议问题