Null out parameters in C#?

后端 未结 6 1133
深忆病人
深忆病人 2021-01-17 11:19

After reading on stackoverflow that in the case of checking the format of a DateTime you should use DateTime.TryParse. After trying some regex expressions they seem to get l

6条回答
  •  清酒与你
    2021-01-17 11:50

    With C#7.0 (since August 2016) you can use the out var construct, and then just ignore the new var in subsequent code.

    bool success = DateTime.TryParse(value, out var result);
    

    If you truly do not care about the value of the result, use discards:

    bool success = DateTime.TryParse(value, out _);
    

提交回复
热议问题