Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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# 当我将(DateTime)放在DataBinder.eval前面时,它会做什么_C#_Asp.net - Fatal编程技术网

C# 当我将(DateTime)放在DataBinder.eval前面时,它会做什么

C# 当我将(DateTime)放在DataBinder.eval前面时,它会做什么,c#,asp.net,C#,Asp.net,当我将(DateTime)放在DataBinder.eval前面时,它会做什么?我还可以将哪些函数放在DataBinder的前面???它只会将.eval方法返回的对象强制转换为DateTime类型。如果无法进行强制转换,将抛出InvalidCastException。关于可以放在DataBinder.Eval前面的函数,几乎可以放任何东西。但是,大多数方法都不起作用。它是从对象投射数据,而对象的Eval将返回到日期时间 // If the cast fails you will get an e

当我将(DateTime)放在DataBinder.eval前面时,它会做什么?我还可以将哪些函数放在DataBinder的前面???

它只会将
.eval
方法返回的对象强制转换为
DateTime
类型。如果无法进行强制转换,将抛出
InvalidCastException
。关于可以放在
DataBinder.Eval
前面的函数,几乎可以放任何东西。但是,大多数方法都不起作用。

它是从
对象
投射数据,而
对象的
Eval
将返回到
日期时间

// If the cast fails you will get an exception
DateTime dt = (DataTime)(DataBinder.Eval("yourfield"));

// If the cast fails you will get null.
DateTime? dt = DataBinder.Eval("yourfield") as DateTime?;

// You could also do which will throw an exception if it fails as well. 
DateTime dt = Convert.ToDateTime(DataBinder.Eval("yourfield"));
有关铸造的详细信息,请参见