宣言
変数
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} };
|
可変長配列
- 可変長配列はArrayテンプレートによって生成されるclass。
定数 - immutable
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
|
-
|
|
|
|
|
!
| #spandel
int[] x1; #spanend
#spandel
int[] x2 = new int[5]; #spanend
#spanadd
immutable int ONE = 1;
#spanend
#spanadd
immutable float TWO = 2.0f;
#spanend
#spanadd
#spanend
#spanadd
pod Vector3
#spanend
#spanadd
{
#spanend
float x;
float y;
float z;
#spanadd
};
#spanend
#spanadd
immutable Vector3 BASIS_Z = {0,0,1};
#spanend
|
連想配列
- 連想配列はHashtableテンプレートによって生成されるclass。
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
32
33
34
35
36
37
38
39
40
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
-
|
|
|
!
|
!
|
|
|
|
| #spanend
#spandel
#spanend
#spandel
int[ char ] x; #spanend
#spanadd
* 変数の属性 - const,ref,in,readonly [#t652f802]
#spanend
#spanadd
''const''
#spanend
- const属性のメンバ関数しか呼ぶことができない。(変数を変更することができない)
#spanadd
#code(c,){{
#spanend
#spanadd
pod Hoge
#spanend
#spanadd
{
#spanend
public int a()const { return 1; }
public int b() { return 2; }
#spanadd
#spanend
static void test()
{
const Hoge hoge;
hoge.a();
hoge.b();
}
#spanadd
};
#spanend
#spanadd
#spanend
|
型推論 - auto
ref
- 参照型。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
|
-
|
|
-
|
!
|
|
-
|
|
!
|
!
| #spanend
#spanadd
pod Hoge
#spanend
#spanadd
{
#spanend
static public void a( ref int b )
{
b = 2;
}
static void test()
{
int hoge = 0;
Hoge.a( hoge );
}
#spanadd
};
#spanend
#spanadd
#spanend
#spanadd
|
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
-
|
|
|
|
!
-
|
|
|
|
|
-
|
|
|
!
|
|
|
|
-
|
|
|
|
|
!
|
|
|
|
|
|
|
|
!
| #spanend
#spanadd
class Vector2
#spanend
#spanadd
{
#spanend
float x;
float y;
#spanadd
};
#spanend
#spanadd
#spanend
#spanadd
class Hoge
#spanend
#spanadd
{
#spanend
#spanadd
public:
#spanend
this()
{
mInt = 2;
@mVec2 = new Vector2();
@mConstVec2 = new Vector2();
}
#spanadd
#spanend
void example()
{
mInt = 3;
@mVec2 = new Vector2();
mVec2.x = 2;
mConstVec2.x = 2;
mVec2.x = mConstVec2.x;
}
#spanadd
private:
#spanend
readonly int mA;
readonly Vector2@ mVec2;
readonly const Vector2@ mConstVec2;
#spanadd
};
#spanend
#spanadd
#spanend
#spanadd
|
ver2以降
型推論 - auto
1
2
3
4
5
6
7
|
-
|
!
| class Hoge
{
void func(){}
}
auto a = new Hoge(); a.func();
|
定数 - enum
可変長配列
- 可変長配列はArrayテンプレートによって生成されるclass。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
| #spandel
enum int ONE = 1;
#spanend
#spandel
enum float TWO = 2.0f;
#spanend
#spanadd
int[] x1; #spanend
#spanadd
int[] x2 = new int[5]; #spanend
#spanadd
|
連想配列
- 連想配列はHashtableテンプレートによって生成されるclass。
pod Vector3
{
float x;
float y;
float z;
};
enum Vector3 BASIS_Z = {0,0,1};
1
2
3
4
5
6
7
|
| #spanend
#spanadd
#spanend
#spanadd
int[ char ] x; #spanend
|
|