这是小程序的源代码:
using System;
class A
{
    public int x;
   public void Main()
    {
        x=5;
        Console.WriteLine("这是x的值{0}", x);
        Console.WriteLine("这是this.x的值{0}", this.x);
    }
}在sdk 通过csc ,通不过,显示:不包含适合于如

解决方案 »

  1.   

    using System;
    class A
    {
        public static int x;
        public static void Main()
        {
            x = 5;
            Console.WriteLine("这是x的值{0}", x);
            Console.WriteLine("这是this.x的值{0}", x);
        }
    }
      

  2.   

    Main函数为静态函数static void Main()
    {
      ...
    }
      

  3.   

    Main 是静态的,
    里面不能用this  也不能用非静态变量, 非静态变量只能用局部的
      

  4.   

    我按照大家的意思改了,可还是通不过:
    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                class A
               {
                    public int x = 5;
                    void yanshi ()
                    {
                        Console.WriteLine ("这是x的值{0}", x);
                        Console .WriteLine ("这是this.x的值{0}", this.x);
                    }
                
                }
               }
             }
       运行后提示:1、应输入}
               2、应输入类型、明明空间定义文件或文件尾这应该如何改。
      

  5.   

    using System; 
    using System.Collections.Generic; 
    using System.Text; namespace ConsoleApplication1 
    {         class Program 
            { 
                static void Main(string[] args) 
                {
                    A a = new A();
                    a.yanshi();
                } 
            }        class A
            {
                public int x;
                public void yanshi()
                {
                    x = 5;
                    Console.WriteLine("这是x的值{0}", x);
                    Console.WriteLine("这是this.x的值{0}", this.x);
                }        } 
    }
      

  6.   

    1.你的程序里确实是少了个}
    2.你这里的this想代指的是什么,类A还是窗体类啊,这是控制台程序,没有窗体类啊,类A也不能这样表示的。
    而且你的主函数里还定义了个新类,不能这样用的啊,综合上述你的提问,我想你想表达的意思应该是:
    namespace 控制台简单小程序
    {
        class Program
        {
            public static int X = 10;
            static void Main(string[] args)
            {
                A a = new A();
                a.X = 5;
                Console.WriteLine("这是x的值{0}", a.X);
                Console.WriteLine("这是this.x的值{0}",X); 
            }
        }
        class A
        {
            private  int x;
            public  int X
            {
                get { return x; }
                set { x = value; }
            }
        }
    }一个是本类的x,另一个是其他类的x。不知道我想的你的问题对不对了