Previous Topic Next topic Print topic


Constructors and Deconstructors - in COBOL and C#

Constructors and Deconstructors in Managed COBOL

class-id SuperHero.
working-storage section.
01 powerLevel binary-long.
method-id new.
procedure division.
    set powerLevel to 0
end method.
 
method-id new.
procedure division using by value powerLevel as binary-long.
    set powerLevel to powerLevel
end method.
method-id Finalize override protected.
    *> Destructor code to free unmanaged resources.
end method.

end class SuperHero.

Constructors and Deconstructors in C#

class SuperHero 
{
  private int _powerLevel;
 
  public SuperHero() 
  {
     _powerLevel = 0;
  }
 
  public SuperHero(int powerLevel) 
  {
    this._powerLevel= powerLevel; 
  }
 
  ~SuperHero() 
  {
    // Destructor code to free unmanaged resources.
    // Implicitly creates a Finalize method
  }
}
Previous Topic Next topic Print topic