Sponsored Ad

Tuesday, April 5, 2011

How to Fix C# Error: Inconsistent accessibility: base class is less accessible than class

When you try to compile below code you will get C# error saying that Inconsistent accessibility: base class 'MyApp.base_class' is less accessible than class 'MyApp.child_class'. This error occurs because public child class is driving from non public base class.

using System;

namespace MyApp
{   
    class base_class
    {
        public base_class()
        {
        }
    }

    public class child_class : base_class
    {
        public child_class()
        {
        }
    }
}

Working version of above code: just add public for base class.

using System;

namespace MyApp
{   
    public class base_class
    {
        public base_class()
        {
        }
    }

    public class child_class : base_class
    {
        public child_class()
        {
        }
    }

}

No comments:

Post a Comment

Development Updates