宣言 
変数 
1
2
3
|
| int x1; int x2 = 1; int x3 = void;
|
固定長配列 
1
2
3
4
5
|
| int[3] x1; int[3] x2 = {0,1,2}; int[3] x3 = {0,1}; int[2][2] x4; int[2][2] x5 = { {0,1} , {2,3} };
|
定数 - immutable 
1
2
3
4
5
6
7
8
9
10
|
-
|
|
|
!
| immutable int ONE = 1;
immutable float TWO = 2.0f;
pod Vector3
{
float x;
float y;
float z;
};
immutable Vector3 BASIS_Z = {0,0,1};
|
変数の属性 - const,ref,in,readonly 
const
- const属性のメンバ関数しか呼ぶことができない。(変数を変更することができない)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
-
|
|
|
|
-
|
|
|
!
!
| pod Hoge
{
public int a()const { return 1; }
public int b() { return 2; }
static void test()
{
const Hoge hoge;
hoge.a(); hoge.b(); }
};
|
ref
- 参照型。Cでいうポインタ。
- 参照は保持することはできない。
- 関数の引数および戻り値でのみ使用可能。
- 戻り値に使う場合,関数ローカルの変数を戻り値として使うことはできない。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
-
|
-
|
!
|
|
-
|
|
!
!
| pod Hoge
{
static public void a( ref int b )
{
b = 2;
}
static void test()
{
int hoge = 0;
Hoge.a( hoge ); }
};
|
in
- 関数の引数でのみ使用可能。
- RealTypeならconst,それ以外ならconst refのエイリアス。
- const,refと併用はできない。
readonly
- C#のものと同じ。
- コンストラクタでしか変更・代入ができないメンバ変数につける属性。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
-
|
|
!
-
|
|
-
|
|
|
!
|
|
-
|
|
|
|
|
!
|
|
|
|
|
!
| class Vector2
{
float x;
float y;
};
class Hoge
{
public:
this()
{
mInt = 2; @mVec2 = new Vector2();
@mConstVec2 = new Vector2();
}
void example()
{
mInt = 3; @mVec2 = new Vector2(); mVec2.x = 2; mConstVec2.x = 2; mVec2.x = mConstVec2.x; }
private:
readonly int mA;
readonly Vector2@ mVec2;
readonly const Vector2@ mConstVec2;
};
|
ver2以降 
型推論 - auto 
1
2
3
4
5
6
7
|
-
|
!
| class Hoge
{
void func(){}
}
auto a = new Hoge(); a.func();
|
可変長配列 
- 可変長配列はArrayテンプレートによって生成されるclass。
1
2
|
| int[] x1; int[] x2 = new int[5];
|
連想配列 
- 連想配列はHashtableテンプレートによって生成されるclass。
|