我建了个类库项目,就一个类文件,代码如下:using System;
using System.Collections.Generic;
using System.Text;namespace topCat
{
    public class Class1
    {
        int aaa = 0;
        aaa=5;//类、结构或接口成员声明中的标记“=”无效 没有提示
    }
}
生成 的时候出现
类、结构或接口成员声明中的标记“=”无效 没有提示
我输完 int aaa = 0;回车再输入 这个变量的时候 ,一般都会有快速提示列表的,但在提示列表里没有这个变量??求解!! 谢谢

解决方案 »

  1.   

    aaa=5
    这样给值是错误,它只能在方法或者函数内给值,
    在外面给值是错误的
      

  2.   

    你对aaa的操作要在方法里写,
        public class Class1
        {
            int aaa = 0;
            aaa=5;//类、结构或接口成员声明中的标记“=”无效 没有提示
        }
    改为public class Class1
        {
            int aaa = 0;
            void set()
            {
               aaa =5;
             }   
    }
      

  3.   

    或者在构造函数中给值也行
    public class Class1
    {
       int aaa=0;
       封装后,在构造函数中赋值
    }用2楼的也可以