How to write nested classes in C#?

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 216
Nested classes are those classes that are contained in another class declarations. The below program in C# will demonstrate this

using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
OuterClass objOuterClass = new OuterClass();
objOuterClass.SayHelloFromOuterClass();
var innerClass = new OuterClass.InnerClass();
innerClass.SayHelloFromInnerClass();
}
}
class OuterClass
{
public void SayHelloFromOuterClass()
{
Console.WriteLine("Hello from Outer Class");
}
public class InnerClass
{
public void SayHelloFromInnerClass()
{
Console.WriteLine("Hello from Inner Class");
}
}
}
}

Comments or Responses

Login to post response