What's so bad about ref parameters?

后端 未结 12 657
隐瞒了意图╮
隐瞒了意图╮ 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:09

    ref is just a tool. You should think: What is the best design pattern for what I am building?

    • Sometimes will be better to use an overloaded method.

    • Others will be better to return a custom type or a tuple.

    • Others will be better to use a global variable.

    • And others ref will be the right decision.

提交回复
热议问题