什么是C#方式相当于这个for循环?

 爱蜜儿小秋秋 发布于 2023-01-31 17:44

我是C#的新手,日复一日地学习它的元素,来自C也让我感到困惑,因为像这样的简单for循环会起作用,所以为什么它不能在C#中工作,如果你能详细解释的话(如果可能的话)我会非常感激.

for (int i = 1; i <= 10; i++){

    public void question()
    {
        if (questionNr == 1)
        {
            questionLabel.Text = "What is Chuck's full name?";
            ans1.Text = "Charles Irving Bartowski";
            ans2.Text = "Charles Richard Bartowski";
            ans3.Text = "Charles Luke Bartowski";
            ans4.Text = "Zachary Strahovski";
        }
        else if (questionNr == 2)
        {
            questionLabel.Text = "Who/what is Orion?";
            ans1.Text = "Original name of the Intersect";
            ans2.Text = "Alias of a secret mission";
            ans3.Text = "Morgan's Xbox";
            ans4.Text = "Chuck's father";
        }

    }

    public void ans1_Click(object sender, EventArgs e)
    {
        if (questionNr == 1)
        {
            pointCounter++;
            pointsLabel.Text = "Current points:" + pointCounter.ToString();
            questionNr++;
        }


    }

    private void ans2_Click(object sender, EventArgs e)
    {
        if (questionNr == 1)
        {
            questionNr++;
        }
    }

    private void ans3_Click(object sender, EventArgs e)
    {
        if (questionNr == 1)
        {
            questionNr++;
        }
    }

    private void ans4_Click(object sender, EventArgs e)
    {
        if (questionNr == 1)
        {
            questionNr++;
        }
    }

}

Eric Lippert.. 7

C#文件的词法结构必须是:

namespace
    class
        method
            statement

A for是一个声明,但您已将其放在方法之外.把它放在方法里面.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有