Solved

calling destructor of base class without calling destructor of derived class in c#  ,.net

Posted on 2009-07-06
3
187 Views
Last Modified: 2012-05-07
can we call a destructor of base class without calling destructor of derived class
using System;

class A

{

 public A()

 {

  Console.WriteLine("Creating A");

 }

 ~A()

 {

  Console.WriteLine("Destroying A");

 }

}
 

class B:A

{

 public B()

 {

  Console.WriteLine("Creating B");

 }

 ~B()

 {

  Console.WriteLine("Destroying B");

 }
 

}

class C:B

{

 public C()

 {

  Console.WriteLine("Creating C");

 }
 

 ~C()

 {

  Console.WriteLine("Destroying C");

 }

}

class App

{

 public static void Main()

 {

  C c=new C();

  Console.WriteLine("Object Created ");

  Console.WriteLine("Press enter to Destroy it");

  Console.ReadLine();

  c=null;

  //GC.Collect();

  Console.Read();

 }
 

}

Open in new window

0
Comment
Question by:Saini_Vikas
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Richard Lee earned 50 total points
ID: 24787799
Calling the destructor of a derived class without calling the destructor of the base class would be incorrect. If a class is built from another house if you destroy it then everything should be destroyed.

If you want another behaviour then you need to consider other option of Object Oriented programming such as Aggregation or Composition.
0
 

Author Closing Comment

by:Saini_Vikas
ID: 31618561
Hi ,
Please providesolution  with some satisfactory answer.
0
 
LVL 18

Expert Comment

by:Richard Lee
ID: 24796110
50 points do not warrant that. Please ask the question and provide the person answering some incentive,
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why, and when, to use Windows Workflow 1 31
How to measure sizes and angles in scanned images ? 3 52
Iterate a dictionnary to change values 4 53
Error in JQuery 5 37
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now