日期:2014-05-17  浏览次数:20667 次

构造函数提示没有访问权限,这个编译错误是什么意思?
下面的代码编译错误:

    public class c
    {
        c() { Console.WriteLine("ctor"); }
        ~c() { Console.WriteLine("dtor"); }
    };
    class Program
    {
        static void Main(string[] args)
        {
            c o1 = new c();
        }
    }

error CS0122: 'cs_ConsoleApplication1.c.c()' is inaccessible due to its protection level
error CS1674: 'cs_ConsoleApplication1.c': type used in a using statement must be implicitly convertible to 'System.IDisposable'

这到底是什么意思呢? 我的代码极其简单啊,错误在哪里?

------解决方案--------------------

public class c
    {
        public c() { Console.WriteLine("ctor"); }
        public ~c() { Console.WriteLine("dtor"); }
    };
    class Program
    {
        static void Main(string[] args)
        {
            c o1 = new c();
        }
    }

------解决方案--------------------
1、lz看c++的书学c#
2、析构函数不允许public 修饰
------解决方案--------------------

public class c
{
    public c() { Console.WriteLine("ctor"); }
    ~c() { Console.WriteLine("dtor"); }