加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c#类,结构或接口成员声明中的’while’标记无效(while循环不起作

发布时间:2020-12-16 01:59:38 所属栏目:百科 来源:网络整理
导读:参见英文答案 Invalid token ‘while’ in class,struct,or interface member declaration in very simple code????????????????????????????????????5个 我是c#的新手但对c非常熟悉,但这个错误对我来说没有多大意义,因为我已经特别遵循了 http://msdn.micro
参见英文答案 > Invalid token ‘while’ in class,struct,or interface member declaration in very simple code????????????????????????????????????5个
我是c#的新手但对c非常熟悉,但这个错误对我来说没有多大意义,因为我已经特别遵循了 http://msdn.microsoft.com/en-us/library/2aeyhxcd.aspx所示的必要语法

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
    int years = 1;
    while (years <=10) {

    public Form1()
    {
        InitializeComponent();
    }

    private void numericUpDown1_ValueChanged(object sender,EventArgs e)
    {
        int value = Convert.ToInt32(bushels1.Text);
        numericUpDown1.Maximum = value;
    }

    private void bushels1_Click(object sender,EventArgs e)
    {

    }

    private void nextYear_Click(object sender,EventArgs e)
    {

    }
    }
   }
}

解决方法

你有直接在类里面,它应该是一个方法的一部分,你不能直接在类内部编写语句.

public partial class Form1 : Form
{
    int years = 1;
    while (years <=10) {
   //^^

它应该是方法的一部分,如:

public partial class Form1 : Form
{
    int years = 1;
    public void SomeMethod()
    {
       while (years <=10) {
      //rest of your code
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读