首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#跳转语法错,该如何解决

2013-07-20 
C#跳转语法错以下是C#代码,跳转出错,如何解决截图如下:全部代码如下:public void Init_Info(){string str

C#跳转语法错
以下是C#代码,跳转出错,如何解决
截图如下:
C#跳转语法错,该如何解决
全部代码如下:


public void Init_Info()
    {
        string str="";
        int num = 1;
        do
        {
            this.selweek.Items.Add(new ListItem(StringType.FromInteger(num), StringType.FromInteger(num)));
            num++;
        }
        while (num <= 0x35);
        num = 6;
        while ((num.ToString()).Length != 1)
        {
            str = num.ToString();
        Label_003C:
            this.selhour.Items.Add(new ListItem(str, str));
            num++;
            if (num <= 0x15)
            {
                continue;
            }
            num = 0;
            goto Label_00EA;
        Label_005E:
            str = "0" + (num);
            goto Label_003C;
        }
        goto Label_005E;
    Label_00EA:
        if ((num % 5) == 0)
        {
            if ((num.ToString()).Length == 1)
            {
                str = "0" + (num);


            }
            else
            {
                str = num.ToString();
            }
            this.selmin.Items.Add(new ListItem(str, str));
        }
        num++;
        if (num > 0x3b)
        {
            int num2=0;
            string str3="";
            string str4="";
            string str6="";
            string str8="";
            SqlConnection objconn = new SqlConnection();
            new refresher.publicclass().opendb(objconn);
            string selectCommandText = "select distinct id,course_name from Ed_tblcourse";
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, objconn);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            DataTable table = new DataTable();
            table = dataSet.Tables[0];
            if ((table.Rows.Count % 8) == 0)
            {
                num2 = table.Rows.Count / 8;
            }
            else
            {


                num2 = (table.Rows.Count / 8) + 1;
            }
            if (table.Rows.Count > 0)
            {
                int num3 = num2 - 1;
                for (num = 0; num <= num3; num++)
                {
                    this.tr = new HtmlTableRow();
                    int num4 = ((num + 1) * 8) - 1;
                    for (int i = num * 8; i <= num4; i++)
                    {
                        if (i < table.Rows.Count)
                        {
                            this.td = new HtmlTableCell();
                            this.td.InnerHtml = StringType.FromObject(ObjectType.StrCatObj(ObjectType.StrCatObj(ObjectType.StrCatObj(("<input type='checkbox' id='chsub" + StringType.FromInteger(i) + "' name='chsub") + StringType.FromInteger(i) + "'  value='", table.Rows[i]["course_name"]), "'>"), table.Rows[i]["course_name"]));
                            this.tr.Cells.Add(this.td);
                        }


                    }
                    this.tblsubject.Rows.Add(this.tr);
                }
            }
            SqlConnection connection2 = new SqlConnection();
            refresher.publicclass publicclass2 = new refresher.publicclass();
            publicclass2.opendb(connection2);
            object currentyear = str3;
            object currentterm = str4;
            this.publicclass.GetCurrentTime(ref currentyear, ref currentterm);
            str4 = StringType.FromObject(currentterm);
            str3 = StringType.FromObject(currentyear);
            string str5 = StringType.FromObject(new SqlCommand(" select convert(char(10),[time],20) as fgaf from tblcurrentYear_Kaixue_Time where term='" + str4 + "'", connection2).ExecuteScalar());
            if (StringType.StrCmp(str5, "", false) == 0)
            {
                str5 = Strings.Format(DateTime.Now, "yyyy-MM-dd");
            }
            publicclass2.closedb(connection2);
            DateTime begintime = DateType.FromString(str5);
            DateTime currenttime = DateType.FromString(Strings.Format(DateTime.Now, "yyyy-MM-dd").ToString());
            int week = 0; //IntegerType.FromString(str6);
            this.GetweeksforTime(begintime, currenttime, ref week);


            str6 = StringType.FromInteger(week);
            this.selweek.Value = str6;
            string str7 = DateTime.Now.Year.ToString() + "年1月1日";
            Convert.ToDateTime(str7);
            week = 0;// IntegerType.FromString(str8);
            this.GetweeksforTime(DateType.FromString(str7), begintime, ref week);
            str8 = StringType.FromInteger(week);
            this.WeekGetDay(int.Parse(str8) + int.Parse(str6));
        }
        else
        {
            goto Label_00EA;
        }
    }


[解决办法]
别用goto吧。用goto即使改出来了,以后维护的时候也不方便。

你这段的代码逻辑及其混乱。
while ((num.ToString()).Length != 1)
{
}
goto Label_005E;
看上面一段,当num长度是1的时候,执行goto Label_005E。但是Label_005E的定义在while循环中,所以编译器因为找不到Label_005E的定义出错。
即使忽略这个错误,Label_005E中跳转到Label_003C,你没发现Label_003C中有continue吗,你要知道你现在又不在循环里面,continue干什么?
[解决办法]
建议用if else 吧,不要用goto
[解决办法]
goto 不要随便用,不然跳着跳着就不知道跳到哪了,你那个goto明显是当条件不成立时跳,但是你却在循环你跳了···
[解决办法]
这个代码是个奇迹,楼主还是赶紧重构吧
循环外是不能跳到循环内的吧

热点排行