プログラムの構造

このヘルプでは、COBOL、C#、VB.NET の間にあるプログラム構造の相違点について説明します。

COBOL のプログラム構造

      $set sourceformat(free)
      $set ilusing"System"
      $set ilnamespace"Hellow"
      *> ilnamespace sets the namespace for entire file
      *> rather than enclosing a source code scope
class-id HelloWorld.
  method-id main static.
  01 nam string.
  procedure division using by value args as string occurs any.
      *> See if an argument was passed from the command line
      if args::Length = 1
          set nam to args(1)
      end-if
      display "Hello, ", nam, "!"
      *> or, if preferred...
      invoke type Console::WriteLine(string::Concat("Hello, ", nam, "!"))
   end method.
end class.

C# のプログラム構造

using System;
 
namespace Hello 
{
   public class HelloWorld 
   {
      public static void Main(string[] args) 
      {
         string name = "C#";
         // See if an argument was passed from the command line
         if (args.Length == 1)
         {
            name = args[0];
         }
         Console.WriteLine("Hello, " + name + "!");
      }
   }
} 

VB.NET のプログラム構造

Imports System
   Namespace Hello
   Class HelloWorld
      Overloads Shared Sub Main(ByVal args() As String)
         Dim name As String = "VB.NET"
         'See if an argument was passed from the command line
         If args.Length = 1 Then
            name = args(0)
         End If
         Console.WriteLine("Hello, " & name & "!")
      End Sub
   End Class
   End Namespace
End Class

これらの例の一部は、ハーディング大学コンピュータ サイエンス学部の Frank McCown 博士が作成したもので、クリエイティブ コモンズ ライセンスに基づいて使用が許可されています。