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

后端 未结 10 2094
暗喜
暗喜 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:14

    Stay away from out. It's there as a low-level convenience. But at a high level, it's an anti-technique.

    int? i = Util.TryParseInt32("1");
    if(i == null)
        return;
    DoSomething(i);
    

提交回复
热议问题