Constructors and Destructors
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp_Shell
{
public class Exercise
{
//default constructor
public Exercise()
{
Console.WriteLine("This is a default constructor");
}
//2nd Constructor with one string paramater
public Exercise(string message)
{
Console.WriteLine(message);
}
//3rd Constructor with two int variables paramaters
public Exercise(int num1, int num2)
{
Console.WriteLine(num1 + num2);
}
//Destructor
~Exercise()
{
Console.WriteLine("Calling Destructor");
Console.ReadLine();
}
}
public class Program
{
public static void Main()
{
//creating 3 instances/objects of class Exeecise
Exercise obj1 = new Exercise();
Exercise obj2 = new Exercise("Hi i am Adeel");
Exercise obj3 = new Exercise(5, 5);
}
}
}
Comments
Post a Comment