C#类和成员(字段,方法等)的默认可见性? [英] Default visibility for C# classes and members (fields, methods, etc.)?

查看:271
本文介绍了C#类和成员(字段,方法等)的默认可见性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找有关C#各个方面的默认可见性的参考。类类型,字段,方法,枚举等。

I'm trying to find a reference for the default visibility of various aspects of C#. Class types, fields, methods, enums, etc.

有人可以提供这些列表以及它们的默认可见性(即没有前缀修饰符)吗?

Can someone provide a list of these along with their default visibility (i.e., no prefixed modifier)?

推荐答案

可以找到您正在查找的所有信息此处 (感谢里德·科普西):

All of the information you are looking for can be found here and here (thanks Reed Copsey):

从第一个链接开始:


在命名空间中直接声明的类和结构 ,而不是嵌套在其他类或结构中),可以是公共的或内部的。 如果未指定访问修饰符,则内部默认为

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.

...


访问权限类成员和结构成员的级别(包括嵌套的类和结构)默认为私有

The access level for class members and struct members, including nested classes and structs, is private by default.

...


接口默认为内部访问

...


代表的行为类似于类和结构。默认情况下,当直接在名称空间中声明时,它们具有内部访问权,而嵌套时具有私有访问权。

Delegates behave like classes and structs. By default, they have internal access when declared directly within a namespace, and private access when nested.






从第二个链接:


From the second link:


顶级类型,不嵌套在其他类型中的文件,只能具有内部或公共可访问性。这些类型的默认可访问性是内部

Top-level types, which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal.

对于嵌套类型:


Members of    Default member accessibility
----------    ----------------------------
enum          public
class         private
interface     public
struct        private

这篇关于C#类和成员(字段,方法等)的默认可见性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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