C# 不一致的可访问性:字段类型“world”的可访问性低于字段“frmSplashScreen”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12990309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:14:16  来源:igfitidea点击:

Inconsistent accessibility: field type 'world' is less accessible than field 'frmSplashScreen

c#fieldrestriction

提问by user1761786

I have this error called Inconsistent accessibility:

我有一个称为不一致可访问性的错误:

field type 'world' is less accessible than field 'frmSplashScreen'

字段类型“world”比字段“frmSplashScreen”更难访问

In my code there is a public partial class called frmSplashScreen

在我的代码中有一个名为的公共部分类 frmSplashScreen

There is also a public class called world

还有一个公共类叫做 world

The line that caused the error was:

导致错误的行是:

private world currentWorld; 

The above line is in the class frmSplashScreen

上面一行是在类中 frmSplashScreen

What is causing the problem?

导致问题的原因是什么?

采纳答案by Leniel Maccaferri

Generally this happens because your field is private. You must change it to public:

通常发生这种情况是因为您的领域是private. 您必须将其更改为public

public world currentWorld;

For more on this, take a look here: Restrictions on Using Accessibility Levels (C# Reference)

有关更多信息,请查看此处:使用辅助功能级别的限制(C# 参考)

回答by BasssS

This can also happen when you have not initialized your class "world" as public

当您尚未将类“world”初始化为 public 时,也会发生这种情况

you should do :

你应该做 :

public class world

Instead of :

代替 :

class world

回答by e0x3

also , I got such an error with publicaccess modifier. The solution was to add {get;set;}getter and setter to properties

另外,我在public访问修饰符时遇到了这样的错误。解决方案是{get;set;}在属性中添加getter 和 setter

回答by manoj

you can't use privateaccess specifier in that statement

您不能private在该语句中使用 访问说明符

    Public class world

will solve this problem

将解决这个问题