C# C-DateTime.TryParse问题-为什么它不喜欢日期的字符串表示形式?

C# C-DateTime.TryParse问题-为什么它不喜欢日期的字符串表示形式?,c#,datetime,tryparse,C#,Datetime,Tryparse,这是我的密码: DateTime Dob = Convert.ToDateTime("1/1/1800"); DateTime Dod = Convert.ToDateTime("1/1/1800"); if (!DateTime.TryParse(p.birthday, out Dob) && !DateTime.TryParse(p.deathday, out Dod)) {

这是我的密码:

            DateTime Dob = Convert.ToDateTime("1/1/1800");
            DateTime Dod = Convert.ToDateTime("1/1/1800");

            if (!DateTime.TryParse(p.birthday, out Dob) && !DateTime.TryParse(p.deathday, out Dod))
            {
                // handle error
            }
p、 生日是:

p、 死亡日为:

当.TryParse代码命中时,我的Dob日期时间对象是:

国防部的DateTime对象是:

问:为什么Dod仍然是我分配的初始值1-1-1800,但Dob设置正确?Dod值2007-02-28是否有不喜欢的地方?

DateTime.TryParsep.birthday,out Dob成功地将字符串转换为DateTime,因此返回true。你用!,给假

当执行到达&&运算符时,它看到第一个操作数已经为false,因此不必麻烦执行第二个操作数

您可以预先执行这两个命令,也可以使用非快捷方式AND运算符&

编辑:或

if (!(DateTime.TryParse(p.birthday, out Dob) || DateTime.TryParse(p.deathday, out Dod)))
{
    ...
}
DateTime.TryParsep.birthday,out Dob成功地将字符串转换为DateTime,因此它返回true。你用!,给假

当执行到达&&运算符时,它看到第一个操作数已经为false,因此不必麻烦执行第二个操作数

您可以预先执行这两个命令,也可以使用非快捷方式AND运算符&

编辑:或

if (!(DateTime.TryParse(p.birthday, out Dob) || DateTime.TryParse(p.deathday, out Dod)))
{
    ...
}

原因是它正在执行!DateTime.TryParsep.birthday,out Dob,返回false。 因此DateTime.TryParsep.deathday,未执行out Dod

http://msdn.microsoft.com/en-us/library/2a723cdk.aspx

x && y

if x is false, y is not evaluated, because the result of the 
AND operation is false no matter what the value of y is. This is known as 
"short-circuit" evaluation.

原因是它正在执行!DateTime.TryParsep.birthday,out Dob,返回false。 因此DateTime.TryParsep.deathday,未执行out Dod

http://msdn.microsoft.com/en-us/library/2a723cdk.aspx

x && y

if x is false, y is not evaluated, because the result of the 
AND operation is false no matter what the value of y is. This is known as 
"short-circuit" evaluation.

你现在的文化是什么?你现在的文化是什么?