Constructor overloading 3

image_pdfimage_print
   

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 */
using System;

namespace Client.Chapter_5___Building_Your_Own_Classes
{
  public class CTORChapter
  {
    public int[] MyIntArray;
    public int Y;
    //Initialization can take place here
    private int ObjectCount = 0;
    static void Main(string[] args)
    {
      CTORChapter X = new CTORChapter();

      X.ObjectCount++;

      CTORChapter YY = new CTORChapter(10);
    }
    //Default CTORChapter
    CTORChapter()
    {
      MyIntArray = new int[10];
      //Do work necessary during object creation
    }
    //Overloads the CTOR allowing you to initialize Y
    CTORChapter(int myY)
    {
      Y = myY;
    }
  }
}