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

后端 未结 22 2893
余生分开走
余生分开走 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:24

    The out keyword is necessary (see SortedDictionart.TryGetValue). It implies pass by reference and also tells the compiler that the following:

    int value;
    some_function (out value);
    

    is OK and that some_function isn't using an unitialised value which would normally be an error.

提交回复
热议问题