Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent Accessability: Base Class is less accessible than class

Tags:

c#

inheritance

I've got the code below and I'm trying to do some inheritance exercises but when I try to run this code it gives me an error:

Inconsistent Accessability: Base Class is less accessible than class

The code:

class Program
{
    static void Main()
    {

        FoodProducts Test = new FoodProducts();

        Test.Limit();



    }
}

public class FoodProducts : Products
{
    public void FoodProduct()
    {
        Console.WriteLine("This is food product");
    }

    public void Limit()
    {
        Console.WriteLine("This is an Attribute of a Product");
    }

}

Would someone be able to help me?

like image 705
user1618490 Avatar asked Aug 27 '12 02:08

user1618490


2 Answers

Just for future reference for someone thick like me, I got this in the following situation and couldn't figure out what was going wrong:

public class Foo : Base<Bar> {} <-- Inconsistent accessibility

public class Base<T> {}

It took me a while to work out that the culprit was here:

internal class Bar {}
like image 160
Benjol Avatar answered Oct 13 '22 18:10

Benjol


What line is the error on, and what is the specific error text? Also, where is the definition of Products?

You are probably getting CS0060: "Inconsistent accessibility: base class 'class1' is less accessible than class 'class2'" Thus, I'm assuming your Products class is not marked as public.

This problem happens when a base class is marked as something other than public (internal, for example), but then you try to make a public derived class.

like image 21
Jonathon Reinhart Avatar answered Oct 13 '22 18:10

Jonathon Reinhart