When is “Try” supposed to be used in C# method names?

前端 未结 6 759
情书的邮戳
情书的邮戳 2020-12-07 11:00

We were discussing with our coworkers on what it means if the method name starts with \"Try\".

There were the following opinions:

  • Use \"Try\" when the
6条回答
  •  -上瘾入骨i
    2020-12-07 11:09

    (Corrected) There is official guideline, as Erik suggested.

    When I see TrySomething method, I assume it

    • doesn't throw
    • returns bool
    • if I expect value, it is returned via 'out' parameter
    • there exists Something method, that allows me to handle any exception myself. (edit, suggested by Jesse Webb)

提交回复
热议问题