16.5 Type declarations

本文介绍了C#中的类型声明,包括类、结构体、接口、枚举和委托声明。这些声明可以作为顶级声明出现在编译单元中,也可以作为成员声明出现在命名空间、类或结构体内部。文章还详细解释了不同类型声明的访问修饰符及其默认访问级别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A type-declaration is a class-declaration (§17.1), a struct-declaration (§1
8.1), an interface-declaration
(§20.1), an enum-declaration (§21.1), or a delegate-declaration (§22.1).
type-declaration:
class-declaration
struct-declaration
interface-declaration
enum-declaration
delegate-declaration
A type-declaration can occur as a top-level declaration in a compilation
unit or as a member declaration
within a namespace, class, or struct.
When a type declaration for a type T occurs as a top-level declaration in a
compilation unit, the fully
qualified name of the newly declared type is simply T. When a type
declaration for a type T occurs within a
namespace, class, or struct, the fully qualified name of the newly declared
type is N.T, where N is the fully
qualified name of the containing namespace, class, or struct.
A type declared within a class or struct is called a nested type (§17.2.6).
The permitted access modifiers and the default access for a type
declaration depend on the context in which
the declaration takes place (§10.5.1):
? Types declared in compilation units or namespaces can have public or
internal access. The default
is internal access.
? Types declared in classes can have public, protected internal, protected,
internal, or
private access. The default is private access.
? Types declared in structs can have public, internal, or private access.
The default is private
access.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值