using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ObjectCreation { class ExampleClass { public static int classCount = 0; public ExampleClass() { classCount++; if (classCount > 2) { throw new Exception("Object creation failed - object creation limited only for one"); } else { Console.WriteLine("Object Created" + classCount); } } public void Display() { Console.WriteLine("object created"); } } class Program { static void Main(string[] args) { ExampleClass ex1 = new ExampleClass(); ExampleClass ex2 = new ExampleClass(); ExampleClass ex3 = new ExampleClass(); ex3.Display(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)