有没有办法抑制不一致的可访问性 [英] Is there any way to suppress Inconsistent accessibility

查看:66
本文介绍了有没有办法抑制不一致的可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表单中,我需要能够创建一个类的多个实例。 我还需要能够遍历它们,例如在List中。

 public static List< Class> ListName 

但是我获得了不一致的可访问性:字段类型'List< Class>'比Form.Class更难访问 通过Form访问类的单个实例很好,但除非使用
列表或数组,否则无法遍历类的多个实例。   这种不一致的可访问性至少可以说是限制性的。 有解决方法吗?

解决方案

您可以将Class实体设置为public:public class Class {}。它可以工作。这是因为你有一些类型的公共方法。但是当你有公共方法并且结果实体不公开时它是不一致的。您可以将方法设置为内部。这意味着
只能从汇编中访问。 


您可以在此链接上阅读有关访问者的信息。


https://docs.microsoft.com/cs-cz/dotnet/csharp/language-参考/关键字/接入修饰语


In a form I need to be able to create multiple instance of a class.  I also need to to be able to iterate through them, such as in a List.

public static List<Class> ListName

But I get Inconsistent accessibility: field type 'List<Class>' is less accessible than Form.Class  Accessing a single instance of the class through the Form is fine, but its not possible to iterate through multiple instance of a class unless using a List or array perhaps.   This inconsistent accessibility is restrictive to say the least.  Is there a workaround?

解决方案

You can set Class entity as public:public class Class{}. It could be worked. It is because you have public method with some type. But it is inconsistency when you have public method and result entity is not public. You can set method as internal. It means it is accessible from assembly only. 

You can read about accessors on this link.

https://docs.microsoft.com/cs-cz/dotnet/csharp/language-reference/keywords/access-modifiers


这篇关于有没有办法抑制不一致的可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆