SiteMap  | About    

What is nested class

The .Net Framework allows you to define a class within another class. Such class is called a nested class. That means a class can be declared within the scope of another class and it is a member of its enclosing class.

class ExternalClass { class NestedClass { NestedClass() { } } }

nested class interview questions and answers c#

The nested types default to private, but can be made public, protected internal, protected, internal, or private. If a class is nested in the public section of a class, it is visible outside the surrounding class. If it is nested in the protected section it is visible in derived classes, if it is nested in the private section, it is only visible for the members of the outer class.

Advantages :

Nested classes have access to the private members of the outer class. It is a way of logically grouping classes that are only used in one place. It increases encapsulation. Nested classes can lead to more readable and maintainable code. It is useful for developing object models in your component.

Can we declare private class in namespace ?

Object oriented propgramming interview questions and answers c#

There are only two valid declarations for a class at the namespace level, "Internal" and "Public". The only exception to this is nested class, where private visibility means that derived classes will have access to the inner class. More about.... private class in name space

In C# -- all nested classes are implicitly static. (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.