
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Nested Classes
A nested class is a class declared in another enclosing class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested class.
Let us see an example code snippet of nested classes in C#.
Example
class One { public int num1; public class Two { public int num2; } } class Demo { static void Main() { One a = new One(); a.num1++; One.Two ab = new One.Two(); ab.num2++; } }
The example shows that class Two is a nested class. The class Two is enclosed inside the class One declaration.
The class Two here is enclosed inside the declaration of class One. Class Two is thus a nested class. Because it has a public accessibility modifier, it can be accessed in places other than class One's scope.
- Related Articles
- Nested Classes in C++
- Nested Classes in Java
- Nested Classes in C#
- Static Nested Classes in Java
- What are nested classes in C#?
- What are the different types of nested classes are defined in Java?
- Pseudo-classes and CSS Classes
- Pseudo-classes and all CSS Classes
- PHP Anonymous classes
- PHP Autoloading Classes
- Bootstrap Contextual classes
- Bootstrap Helper Classes
- PHP Nested Exception
- Python Exception Base Classes
- Storage Classes in C

Advertisements