开发者

What is the default access modifier of a class?

开发者 https://www.devze.com 2023-01-11 16:59 出处:网络
What is th开发者_如何学编程e default access modifier of a class?internal, if defined directly in the namespace (probably most classes):

What is th开发者_如何学编程e default access modifier of a class?


internal, if defined directly in the namespace (probably most classes):

Internal is the default if no access modifier is specified

For classes within other classes, the default is private, like class members:

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

Source: http://msdn.microsoft.com/en-us/library/ms173121.aspx


by Default Internal is the access modifier of class


An enum has default modifier as public

A class has default modifiers as Internal . It can declare members (methods etc) with following access modifiers: public internal private protected internal

An interface has default modifier as public

A struct has default modifier as Internal and it can declare its members (methods etc) with following access modifiers: public internal private

A methods, fields, and properties has default access modifier as "Private" if no modifier is specified.


I believe it's internal.


Normally, the accessibility of a member is not greater than the accessibility of the type that contains it. However, a public member of an internal class might be accessible from outside the assembly if the member implements interface methods or overrides virtual methods that are defined in a public base class.

When a member of a class is a property, field, method, event, or delegate, and that member either is a type or has a type as a parameter or return value, the accessibility of the member cannot be greater than the type. For example, you cannot have a public method M that returns a class C unless C is also public. Likewise, you cannot have a protected property of type A if A is declared as private.


internal, except for for nested types in which case it is private


The default access modifier for a class is internal if it's defined within the same namespace. It is private if it's defined within another class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号