Nested types
You can nest any number of types (including class) in class and structure, but not in Enum.
Class{EnumParserstate {}} class person {class room {}EnumGuntype {}}
View code
Access Modifiers
Internal: Only packages are used in this assemble (classlibrary is DLL after compilation, consoleapplication16 is EXE after compilation, which is two independent assembles.
Other assemblies are invisible.
The above classlibrary1 is a class assembly DLL, class1 is internal, so another assembly applies this DLL, it cannot be new
Private:Non nestType (when class is defined), private cannot be added, and nest is not necessarily. It can only be explicitly public or internal, or the default value is iternal.
ClassPersonparser//Default Value: internal.{Int_ Privatedata;//Default Value: PrivatePrivate EnumParserstate//Explicit: Private{}}
View code
Protect: the inherited class can use protect methord, and the external class cannot be used. In usage, create base class creates several methords. I only want the child class to use these methords. The external classes are not available.
Summary of Public vs private vs protect:
- The picture on the left is private, so it cannot be used by child class or external class. Protect on the right can only be used by child class, and internal can be used by third-digit assembly. Public all visible
- After nest, write type. Type:
- Protected internal: internal to yourself is internal, external is protect (use first inheritance ).
- Both filed and methord in the interface are public.
- Summary: Generally, we recommend that you use the private method whenever possible. If you need multiple Assembly sharing methods to use internal (for example, the reader and writer methods must be used by multiple projects), you need to use other external assemblies before using public.
ImplicitAnd explicitInterface implementations
Implicity:
Explicity: The Use method fullfill in the class tree can be used separately.
When writing an interface, we can use a type to inherit the interface, CTRL +. that is, implicaity creates a public method to associate with the method of the same name as the interface. If you write the explicity yourself, you need to write the interface. in this way, the method is private.
The same object in the interface has different results due to different vaiable types.