如何纠正我这个错误 [英] how to rectify i this errors
本文介绍了如何纠正我这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编译器错误消息:CS0029:无法将类型字符串"隐式转换为"System.DateTime"
源错误:
Compiler Error Message: CS0029: Cannot implicitly convert type ''string'' to ''System.DateTime''
Source Error:
try { // Line 71:
mydate3 = (mydate - mydate2).ToString();
this.Label5.Text = "Time Left: " + mydate3.ToShortTimeString();
} catch (Exception ex) {
编译错误
说明:编译服务该请求所需的资源期间发生错误.请查看以下特定的错误详细信息,并适当地修改您的源代码.
编译器错误消息:CS0266:无法将类型"object"隐式转换为"int".存在显式转换(您是否缺少演员表?)
源错误:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0266: Cannot implicitly convert type ''object'' to ''int''. An explicit conversion exists (are you missing a cast?)
Source Error:
foreach (object x_loopVariable in dt.Rows) { // Line 84:
x= x_loopVariable ;
if (Convert.ToInt32(x["Selected"]) + 1 == Convert.ToInt32(x["correct"])); {
marks += 1;
推荐答案
1.您不能使用赋值表达式将一种类型转换为另一种类型(例如string
到DateTime
),除非该类型具有可以接受源类型的operator=
.
2.执行编译器告诉您的内容.
请查看C#参考手册以获取更多详细信息.
1. You cannot use an assignment expression to convert one type to another (e.g.string
toDateTime
) unless the type has anoperator=
that will accept the source type.
2. Do what the compiler tells you.
Check your C# reference manual for further details.
错误:"CS0029:无法将类型"string"隐式转换为"System.DateTime""
原因:您的以下代码.
mydate3 = (mydate - mydate2).ToString();
我猜mydate3
的类型是DateTime
,并且您正在尝试为其分配类型String
的数据.
解决方案:如下修改代码.
mydate3 = mydate - mydate2;
错误:"CS0266:无法将类型"object"隐式转换为"int"."
原因:您的以下代码.可能您正在尝试将DataRow
的对象分配给int
变量.
x= x_loopVariable ;
Error: "CS0029: Cannot implicitly convert type ''string'' to ''System.DateTime''"
Reason : Your below code.
mydate3 = (mydate - mydate2).ToString();
I guess Type ofmydate3
isDateTime
, and you are trying to assign a data of TypeString
to it.
Resolution: Modify your code as below.
mydate3 = mydate - mydate2;
Error: "CS0266: Cannot implicitly convert type ''object'' to ''int''."
Reason: Your below code. Probably you are trying to assign object ofDataRow
toint
variable.
x= x_loopVariable ;
String Gender;
if (DDGender.SelectedItem.Text = Convert.ToString("--SELECT--" ))
{
Response.Write("Please Select the Gender");
}
else if (DDGender.SelectedItem.Text = "MALE")
{
Gender = DDGender.SelectedItem.Text;
Response.Write("Select Gender" +Gender );
}
else
{
Gender = DDGender.SelectedItem.Text;
Response.Write("Select Gender" + Gender);
}
}
Clarify the error
这篇关于如何纠正我这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文