このヘルプでは、COBOL、C#、VB.NET で使用できるさまざまなデータ型について説明します。
Value Types
condition-value
binary-char (unsigned)
character
binary-short, binary-long, binary-double (unsigned)
float-short, float-long
decimal
DateTime (not a built-in COBOL type)
Reference types
object
string
Initializing
01 correct condition-value value true.
01 b binary-char unsigned value h"2a". *> Hex
01 o binary-char ussigned value o"52". *> Octal
01 person object value null.
01 nam string value "Dwight".
01 grade character value "B".
01 today type DateTime value type DateTime::Parse("12/31/2007 12:15:00").
01 amount decimal value 35.99.
01 gpa float-short value 2.9.
01 pi float-long value 3.14159265.
01 lTotal binary-double value 123456.
01 sTotal binary-short value 123.
01 usTotal binary-short unsigned value 123.
01 uiTotal binary-long value 123.
01 ulTotal binary-long unsigned value 123.
Type Information
01 x binary-long.
display x::GetType *> Prints System.Int32
display type of binary-long *> Prints System.Int32
display x::GetType::Name *> Prints Int32
Type Conversion
01 d float-short value 3.5. *> automatic conversion
set i to d as binary-long *> set to 3 (truncates decimal)
COBOL types not supported in C# or VB.Net
*> Only a few examples here
01 displayNumber pic 9(9).99.
01 computeNumber pic 9(9)V99.
01 alphaNumberic pic a(23).
01 binaryStorage pic x(12).
*> Also groups and redefines - a few examples
01 arecord.
03 aSubRecord pic x(10).
03 aUnion pic 9(10) redefines aSubrecord.
Value Types
bool
byte, sbyte
char
short, ushort, int, uint, long, ulong
float, double
decimal
DateTime (not a built-in C# type)
Reference Types
object
string
Initializing
bool correct = true;
byte b = 0x2A; // hex
object person = null;
string name = "Dwight";
char grade = 'B';
DateTime today = DateTime.Parse("12/31/2007 12:15:00");
decimal amount = 35.99m;
float gpa = 2.9f;
double pi = 3.14159265;
long lTotal = 123456L;
short sTotal = 123;
ushort usTotal = 123;
uint uiTotal = 123;
ulong ulTotal = 123;
Type Information
int x;
Console.WriteLine(x.GetType()); // Prints System.Int32
Console.WriteLine(typeof(int)); // Prints System.Int32
Console.WriteLine(x.GetType().Name); // prints Int32
Type Conversion
float d = 3.5f;
int i = (int)d; // set to 3 (truncates decimal)
Value Types Boolean Byte, SByte Char Short, UShort, Integer, UInteger, Long, ULong Single, Double Decimal Date Reference Types Object String Initializing Dim correct As Boolean = True Dim b As Byte = &H2A 'hex Dim o As Byte = &O52 'octal Dim person As Object = Nothing Dim name As String = "Dwight" Dim grade As Char = "B"c Dim today As Date = #12/31/2007 12:15:00 PM# Dim amount As Decimal = 35.99@ Dim gpa As Single = 2.9! Dim pi As Double = 3.14159265 Dim lTotal As Long = 123456L Dim sTotal As Short = 123S Dim usTotal As UShort = 123US Dim uiTotal As UInteger = 123UI Dim ulTotal As ULong = 123UL Type Information Dim x As Integer Console.WriteLine(x.GetType()) ' Prints System.Int32 Console.WriteLine(GetType(Integer)) ' Prints System.Int32 Console.WriteLine(TypeName(x)) ' Prints Integer Type Conversion Dim d As Single = 3.5 Dim i As Integer = CType(d, Integer) ' set to 4 (Banker's rounding) i = CInt(d) ' same result as CType i = Int(d) ' set to 3 (Int function truncates the decimal)
これらの例の一部は、ハーディング大学コンピュータ サイエンス学部の Frank McCown 博士が作成したもので、クリエイティブ コモンズ ライセンスに基づいて使用が許可されています。