Inner class : Nested Class « Class « C# / CSharp Tutorial






using System;

class MyClass
{
   class MyCounter
   {
      public int Count = 0;
   }

   private MyCounter counter;

   public MyClass() {
      counter = new MyCounter();
   }
   public int Incr() {
      return counter.Count++;
   }
   public int GetValue() {
      return counter.Count;
   }
}

class MainClass
{
   static void Main()
   {
      MyClass mc = new MyClass();

      mc.Incr();
      mc.Incr();
      mc.Incr();
      mc.Incr();
      mc.Incr();
      mc.Incr();

      Console.WriteLine("Total: {0}", mc.GetValue());
   }
}
Total: 6








7.28.Nested Class
7.28.1.class nesting
7.28.2.Nested class object
7.28.3.Inner class