我被撞成两行 [英] i was struk in two line
本文介绍了我被撞成两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Timer1_Tick(object sender, System.EventArgs e)
{
DateTime mydate2 = DateTime.Now;
DateTime mydate3 = default(DateTime);
try {
mydate3 = (mydate - mydate2).ToString();
this.Label5.Text = "Time Left: " + mydate3.ToShortTimeString();
} catch (Exception ex) {
this.Label5.Text = "Error Setting up the Timer. Contact Admin";
}
if (mydate3.ToShortTimeString() == "00:00:00") {
int marks = 0;
Session["Answered"]=dt ;
foreach (object x_loopVariable in dt.Rows) {
x=x_loopVariable ;
if (x("Selected") + 1 == x("correct")) {
marks += 1;
}
}
我在此代码中出现错误:
I got errors in this code:
mydate3 = (mydate - mydate2).ToString();
foreach (object x_loopVariable in dt.Rows) {
x=x_loopVariable ;
if (x("Selected") + 1 == x("correct")) {
marks += 1;
推荐答案
mydate3 = (mydate - mydate2).ToString(); // ToString returns a String.
mydate3
是DateTime
尝试为其分配String
.
mydate3
is a DateTime
and you are trying to assign a String
to it.
if (x("Selected") + 1 == x("correct")
您可能需要将x("Selected")
和x("correct")
明确转换为int
s.它们现在是object
s.
You might need to explicitly convert x("Selected")
and x("correct")
to int
s. They are now object
s.
if (Convert.ToInt32(x("Selected")) + 1 == Convert.ToInt32(x("correct"))
c#中的索引访问器位于方括号之间,而不是括号=>
Index accessors in c# are between brackets and not parenthesis =>
if (Convert.ToInt32(x["Selected"]) + 1 == Convert.ToInt32(x["correct"])
这篇关于我被撞成两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文