C# Distructor Issue

Mar 24 2019 1:25 PM
I have an issue in my code which is : 
 
i have 2 classes Parent and Child
  1. class Parent    
  2. {    
  3.    List<Child>  Childs1 = new List<Child>();    
  4.    List<Child>  Childs2 = new List<Child>();    
  5.    Parent()    
  6.    {    
  7.       // Some Code     
  8.    }    
  9.    ~Parent()    
  10.    {    
  11.        Console.WriteLine("Hello World!!");    
  12.    }     
  13. }    
  14.      
  15. class Child    
  16. {    
  17.    // Some Code     
  18. }
 // Output :-
 
 Hello World!!
 Hello World!!
 
- Why the parent distructor is been called twice when  instantiated in the main after the           program is closed?

Answers (2)