Hi,
I have created a container class with two public nested class, The constructor or static constructor is never getting called. How are we able to access nested class like accessing a static variable even thought the class is not static.Please check the code below.
using System; namespace NestedClass { class Program { static void Main(string[] args) { Container.ChildContainer.Text = "Some value"; Container.StaticChildContainer.Text = "Some value"; Container.ChildContainer childContainer = new Container.ChildContainer(); childContainer.Input = "Some Input"; Console.ReadKey(); } } public class Container { public static string Text { get; set; } public string Input { get; set; } static Container() { Console.WriteLine("Container Static Constructor"); } public Container() { Console.WriteLine("Container Static Constructor"); } public class ChildContainer { public static string Text { get; set; } public string Input { get; set; } public ChildContainer() { Console.WriteLine("ChildContainer Constructor"); } static ChildContainer() { Console.WriteLine("ChildContainer static Constructor"); } } public static class StaticChildContainer { public static string Text { get; set; } static StaticChildContainer() { Console.WriteLine("StaticChildContainer static Constructor"); } } } }