private bool ValidDateCheck(){
bool _isValid = true;
try{
DateTime.Parse("07/&*/2009");
DateTime d = Convert.ToDateTime("07/&*/2009");
}
catch{
_isValid = false;
}
return _isValid;
}
上面的代码如何不抛出异常?
最佳答案
这是来自 .NET 1.1 documentation :
The string s is parsed using the formatting information in a DateTimeFormatInfo initialized for the current culture.
This method attempts to parse s completely and avoid throwing FormatException. It ignores unrecognized data if possible and fills in missing month, day, and year information with the current time. If s contains only a date and no time, this method assumes 12 A.M. Any leading, inner, or trailing white space character in s is ignored.
Parameter s must contain the representation of a date and time in one of the formats described in the DateTimeFormatInfo topic.
我无法对此进行测试,因为我可以在 VS2008 中构建的最早版本是 2.0。
关于c# - 为什么这个日期解析在 C# .net 1.1 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1614926/