型の比較
データ型
整数
| |
符号あり |
符号なし |
| C++ |
int |
unsigned int |
| C++/CLI |
int※1 |
unsigned int |
| System::Int32 |
System::UInt32 |
| C# |
int※1 |
uint |
| System.Int32 |
System.UInt32 |
| Java |
int |
--- |
| java.lang.Integer |
--- |
※1 intはSystem.Int32構造体の別名であり、実体は構造体です。
バイト数による比較
C++/CLIは、unmanagedはC++に、managedはC#と同じです。
符号あり整数
| バイト数 |
C++ |
C# |
Java |
| 1 |
char |
sbyte |
System.Sbyte |
byte |
| 2 |
wchar_t |
char |
System.Char |
--- |
| 2 |
short |
short |
System.Int16 |
short |
| 4 |
int |
int |
System.Int32 |
int |
| 4 |
long |
--- |
--- |
| 8 |
__int64 |
long |
System.Int64 |
long |
符号なし整数
| バイト数 |
C++ |
C# |
Java |
| 1 |
unsigned char |
byte |
System.Byte |
--- |
| 2 |
unsigned short |
ushort |
System.Uint16 |
char |
| 4 |
unsigned int |
uint |
System.Uint32 |
--- |
| 8 |
--- |
ulong |
System.Uint64 |
--- |
浮動小数点数型
| バイト数 |
C++ |
C# |
Java |
| 4 |
float |
float |
System.Single |
float |
| 8 |
double |
double |
System.Double |
double |
| 16 |
--- |
decimal |
System.Decimal |
--- |
名前付定数 (named constant)
キーワード
| 初期値 |
定数 |
定数または変数 |
| 初期化タイミング |
コンパイル時 |
実行時 |
| C++ |
const |
--- |
--- |
| C++/CLI |
const |
literal |
initonly |
| C# |
--- |
const |
readonly |
| Java |
--- |
final |
--- |
キャスト (type casting)
| |
チェックなし |
失敗時にNULLを返す |
失敗時に例外を投げる |
| C++ |
() キャスト演算子 |
static_cast |
dynamic_cast※1 |
dynamic_cast※2 |
| C++/CLI |
dynamic_cast※2 |
| safe_cast |
| C# |
--- |
as演算子 |
() キャスト演算子 |
※1 参照型の場合は、例外を投げます。
※2 ポインタの場合は、NULLを返します。
特殊なキャスト
| |
const、volatile の削除と付加 |
ポインタ型の変換 |
| C++ |
const_cast |
reinterpret_cast |
| C++/CLI |
const_cast |
reinterpret_cast |
| C# |
--- |
--- |
型情報の取得
| |
インスタンスから取得 |
クラス名から取得 |
| C++ |
type_info& type = typeid( obj );
※typeinfoヘッダをインクルードする必要があります。
|
--- |
| C++/CLI |
Type^ type = obj->GetType(); |
Type^ type = Type::GetType( "String" );
または
Type^ type = String::typeid;
(typeid演算子)
|
| C# |
Type type = obj.GetType(); |
Type type = Type.GetType( "String" );
または
Type type = typeof( "String" );
(typeof演算子)
|