Objects - in COBOL and C# and VB.NET

C# COBOL VB.NET
SuperHero hero = new SuperHero();



// No "With" construct
hero.Name = "SpamMan";
hero.PowerLevel = 3;


hero.Defend("Laura Jones");
SuperHero.Rest();   // Calling static method



SuperHero hero2 = hero;   // Both reference the same object 
hero2.Name = "WormWoman";
Console.WriteLine(hero.Name);   // Prints WormWoman

hero = null ;   // Free the object

if (hero == null)
  hero = new SuperHero();

Object obj = new SuperHero();
if (obj is SuperHero)
{
  Console.WriteLine("Is a SuperHero object.");
}



// Mark object for quick disposal
using (StreamReader reader = File.OpenText("test.txt"))
{
  string line;
  while ((line = reader.ReadLine()) != null)
  {
    Console.WriteLine(line);
  }
}
    declare hero = new SuperHero
    declare hero2 as type SuperHero
    declare obj as object
    declare lin as string

*> No "With" construct
    set hero::Name to "SpamMan"
    set hero::PowerLevel to 3


    invoke hero::Defend("Laura Jones")
    invoke type SuperHero::Rest   *> Calling static method



    set hero2 to hero      *> Both reference the same object
    set hero2::Name to "WormWoman"
    display hero::Name   *> Prints WormWoman

    set hero to null       *> Free the object

    if hero = null
        set hero to new SuperHero
    end-if

    set obj to new SuperHero
    if obj is instance of type SuperHero
        display "Is a SuperHero object."
    end-if

   end program.

    class-id SuperHero.
    01 #Name string property.
    01 PowerLevel binary-long property.
    method-id Defend (defendee as string).
    end method.
    method-id Rest static.
    end method.
    end class.
Dim hero As SuperHero = New SuperHero
' or
Dim hero As New SuperHero

With hero
  .Name = "SpamMan"
  .PowerLevel = 3
End With
hero.Defend("Laura Jones")
hero.Rest() ' Calling Shared method
' or
SuperHero.Rest()

Dim hero2 As SuperHero = hero  ' Both reference the same object 
hero2.Name = "WormWoman"
Console.WriteLine(hero.Name)   ' Prints WormWoman

hero = Nothing    ' Free the object

If hero Is Nothing Then _
  hero = New SuperHero

Dim obj As Object = New SuperHero
If TypeOf obj Is SuperHero Then _
  Console.WriteLine("Is a SuperHero object.")






' Mark object for quick disposal
Using reader As StreamReader = File.OpenText("test.txt")
  Dim line As String = reader.ReadLine()
  While Not line Is Nothing
    Console.WriteLine(line)
    line = reader.ReadLine()
  End While
End Using