Why are 'out' parameters in .NET a bad idea?

后端 未结 22 2898
余生分开走
余生分开走 2020-12-25 10:54

Why are \'out\' parameters in .NET a bad idea?

I was recently asked this, but I had no real answer besides it\'s simply unnecessarily complicating an application. Wh

22条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-25 11:16

    Well, they aren't a bad idea I think. Dictionary has a TryGetValue method which is a very good example why out parameters are sometimes a very nice thing to have.

    You should not overuse this feature of course, but it's not a bad idea per definition. Especially not in C# where you have to write down the out keyword in function declaration and call which makes it obvious what's going on.

提交回复
热议问题