Null out parameters in C#?

后端 未结 6 1137
深忆病人
深忆病人 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:58

    If you are using .NET 3 and above, you could always create an Extension method?

    public static bool IsValidDate(this string value)
    {
      DateTime date = DateTime.Null;
      return DateTime.TryParse(value, out date);
    }
    

    [Edited to rename the method name to a more appropriate one]

提交回复
热议问题