このヘルプでは、COBOL、C#、VB.NET の間にある構造の相違点について説明します。
$set sourceformat(free)
*> COBOL uses valuetype-id to define a value type
valuetype-id StudentRecord.
01 #name string public.
01 gpa float-short public.
method-id new.
procedure division using by value nam as string, gpa as float-short.
set #name to nam
set self::"gpa" to gpa
end method.
end valuetype StudentRecord.
class-id a.
method-id main static.
01 stu type StudentRecord value new StudentRecord("Bob", 3.5).
01 stu2 type StudentRecord.
set stu2 to stu
set stu2::name to "Sue"
display stu::name *> Prints Bob
display stu2::name *> Prints Sue
end method.
end class a.
// C# uses struct to define a value type
struct StudentRecord
{
public string name;
public float gpa;
public StudentRecord(string name, float gpa)
{
this.name = name;
this.gpa = gpa;
}
}
StudentRecord stu = new StudentRecord("Bob", 3.5f);
StudentRecord stu2 = stu;
stu2.name = "Sue";
Console.WriteLine(stu.name); // Prints Bob
Console.WriteLine(stu2.name); // Prints Sue
' VB Users Structure to define a value type
Structure StudentRecord
Public name As String
Public gpa As Single
Public Sub New(ByVal name As String, ByVal gpa As Single)
Me.name = name
Me.gpa = gpa
End Sub
End Structure
Dim stu As StudentRecord = New StudentRecord("Bob", 3.5)
Dim stu2 As StudentRecord = stu
stu2.name = "Sue"
Console.WriteLine(stu.name) ' Prints Bob
Console.WriteLine(stu2.name) ' Prints Sue
これらの例の一部は、ハーディング大学コンピュータ サイエンス学部の Frank McCown 博士が作成したもので、クリエイティブ コモンズ ライセンスに基づいて使用が許可されています。