What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 6991 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > C# > Constructor and Destructor ...
Ranjeet_8

Constructor and Destructor

 Code Snippet posted by: Ranjeet_8 | Posted on: 3/1/2013 | Category: C# Codes | Views: 373 | Status: [Member] | Points: 40 | Alert Moderator   




class Program
{
static void Main(string[] args)
{
Three t = new Three();
Console.ReadLine();

}
}



class One
{
//Constructor
public One()
{
Console.WriteLine("First Constructor Called");
}

//Destructor
~One()
{
Console.WriteLine("First destructor is called.");
Console.ReadLine();
}
}








class Two : One
{
//Constructor
public Two()
{
Console.WriteLine("Second Constructor Called");

}
//Destructor
~Two()
{
Console.WriteLine("Second destructor is called.");

}
}

class Three : Two
{
//Constructor
public Three()
{
Console.WriteLine("Third Constructor Called");
}
//Destructor
~Three()
{
Console.WriteLine("Third destructor is called.");

}
}



/*The result of this Program will be:-
First Constructor Called
Second Constructor Called
Third Constructor Called

Third destructor is called.
Second destructor is called.
First destructor is called.
*/

Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 1:13:59 AM