Previous Topic Next topic Print topic


Constructors and Destructors - in COBOL and C# and VB.NET

C# COBOL VB.NET
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
  }
}
class-id Heater.
01 _powerLevel binary-long.

method-id new.
    set _powerLevel to 0
end method.

method-id new (powerLevel as binary-long).
    set _powerLevel to powerLevel
end method.

$if JVMGEN set
method-id Finalize override protected.
    *> JVM finalizer method. 
end method.
$else
method-id Finalize override protected.
    *> .NET finalizer method. 
end method.
$end
end class.
Class SuperHero
  Private _powerLevel As Integer

  Public Sub New()
    _powerLevel = 0
  End Sub

  Public Sub New(ByVal powerLevel As Integer)
    Me._powerLevel = powerLevel
  End Sub

  Protected Overrides Sub Finalize()
   ' Desctructor code to free unmanaged resources 
    MyBase.Finalize()
  End Sub
End Class
Previous Topic Next topic Print topic