首页 新闻 赞助 找找看

“a”中的成员名不能与它的封闭类型相同,如何解决?

0
[已解决问题] 解决于 2013-04-02 00:26
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class a
    {
        static void Main(string[] args);
       
            public class student
            { public double  s_allow;
                public  static readonly student Bachelor;
                public student (double allow)
                {this.s_allow =allow ;

                }
                static  student ()
                { Bachelor =new student (200);



                }

            
            
            }

        class a
        {static void Main(string[] args);
            student student1=student.Bachelor ;
           // Console.WriteLine ("该学生每月津贴为: {0}",student1.s_allow);
            //Console.ReadLline ();
        
        }

        }
    }
“a”中的成员名不能与它的封闭类型相同,这个问题应该怎么解决呢?怎么样才能实现我想要的功能,求高手指点迷津
I love 小丽子的主页 I love 小丽子 | 菜鸟二级 | 园豆:206
提问于:2013-03-31 01:40
< >
分享
最佳答案
0

按照你的代码的意图,应该是把Student类写到a类的外面

正确的代码是

using System;     //这里只要using System就可以了,其他的都可以不要


namespace ConsoleApplication1
{
    public class student
    { 
        public double  s_allow;
        public  static readonly student Bachelor;
        public student (double allow)
        {
                this.s_allow =allow ;
        }
         static  student ()
         { 
               Bachelor =new student (200);
          }
      }
    
    class a
    {
        static void Main(string[] args)
        {
            student student1=student.Bachelor ;
           Console.WriteLine ("该学生每月津贴为: {0}",student1.s_allow);
            Console.ReadLline ();
        }

     }
}                    

顺便你的不良代码风格我就不吐槽了

奖励园豆:5
飞鸟_Asuka | 菜鸟二级 |园豆:209 | 2013-03-31 20:52
其他回答(3)
0

定义了2个main函数,main函数是程序运行的入口

chenping2008 | 园豆:9836 (大侠五级) | 2013-03-31 10:02

上面不是已经定义过了吗?

支持(0) 反对(0) I love 小丽子 | 园豆:206 (菜鸟二级) | 2013-03-31 11:43

但是同样会出现那样的问题

具体应该怎么弄个呢?我是个刚刚初学的人对这些还不是很懂,如有你的帮助真是太感谢了

支持(0) 反对(0) I love 小丽子 | 园豆:206 (菜鸟二级) | 2013-03-31 11:45
0

这个代码根本不能看...我只是吐槽一下... 

S-Lyy | 园豆:257 (菜鸟二级) | 2013-04-01 09:37
0

看着有点云里雾里的。

jerry-Tom | 园豆:4077 (老鸟四级) | 2013-04-01 14:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册