Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 c中的类型转换问题_C# 4.0_Casting_Nullable - Fatal编程技术网

C# 4.0 c中的类型转换问题

C# 4.0 c中的类型转换问题,c#-4.0,casting,nullable,C# 4.0,Casting,Nullable,我有类型转换问题,我需要尽快得到帮助:D,现在的问题是检查datetime和int类型的可空值的ive方法。。。但我得到类型转换错误 方法: public static DateTime? ToNullableDateTime(string stringValue) { DateTime dateValue; if (DateTime.TryParse(stringValue, out dateValue)) { return dateValue;

我有类型转换问题,我需要尽快得到帮助:D,现在的问题是检查datetime和int类型的可空值的ive方法。。。但我得到类型转换错误

方法:

    public static DateTime? ToNullableDateTime(string stringValue)
    {
        DateTime dateValue;
        if (DateTime.TryParse(stringValue, out dateValue)) { return dateValue; } 
     else {     return DateTime.MinValue; }
    }
在我的对象类中使用其方法:

 Objects<DateTime?>.ToNullableDateTime(((Label)gvRow.FindControl("lblCommitmentDate")).Text);
错误:


无法将类型“System.DateTime”隐式转换为“System.DateTime”。存在显式转换。是否缺少强制转换

您正在定义DateTime的返回类型?并尝试返回日期时间。

为什么不在方法中返回日期时间?