When should I use out parameters?

后端 未结 10 1297
温柔的废话
温柔的废话 2020-12-08 06:34

I don\'t understand when an output parameter should be used, I personally wrap the result in a new type if I need to return more than one type, I find that a lot easier to w

10条回答
  •  一整个雨季
    2020-12-08 06:58

    It does annoy me that I can't pass in null to the out parameter for the TryParse functions.

    Still, I prefer it in some cases to returning a new type with two pieces of data. Especially when they're unrelated for the most part or one piece is only needed for a single operation a moment after. When I do need to save the resulting value of a TryParse function I really like having an out parameter rather than some random ResultAndValue class that I have to deal with.

提交回复
热议问题