Best practice of using the “out” keyword in C#

后端 未结 10 2133
暗喜
暗喜 2020-12-16 11:53

I\'m trying to formalise the usage of the \"out\" keyword in c# for a project I\'m on, particularly with respect to any public methods. I can\'t seem to find any best practi

10条回答
  •  感动是毒
    2020-12-16 12:03

    Your approach is better than out, because you can "chain" calls that way:

    DoSomethingElse(DoThing(a,b).Result);
    

    as opposed to

    DoThing(a, out b);
    DoSomethingElse(b);
    

    The TryParse methods implemented with "out" was a mistake, IMO. Those would have been very convenient in chains.

提交回复
热议问题