不一致的可访问性:基类比类不易访问 [英] Inconsistent Accessability: Base Class is less accessible than class
问题描述
我已经得到了下面的代码,我正在尝试进行一些继承练习,但是当我尝试运行此代码时,它会给我一个错误:
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
代码:
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");
}
}
有人能帮我吗?
推荐答案
错误是什么行,具体的错误文本是什么?此外,产品
的定义在哪里?
What line is the error on, and what is the specific error text? Also, where is the definition of Products
?
你可能会得到CS0060 :不一致的可访问性:基类'class1'比类'class2'更难访问因此,我假设你的产品
类未标记为 public
。
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
.
此问题发生在基类被标记为 public
(例如 internal
)以外的其他类,但是你尝试制作一个 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.
这篇关于不一致的可访问性:基类比类不易访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!