0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

(C#)配列の宣言時、要素数を変数で指定する方法。

Last updated at Posted at 2021-03-01

C#はマクロ定義ができないそうですね。

同じ要素数の配列を何度も宣言したいと思い、変数名を要素数に入力してみたんですがうまくいきませんでした。

int maxObjectNum = 10;
Object[] Objects = new Object[maxObjectNum];

上のように変数で指定するとエラーですが、

const int maxObjectNum = 10;
Object[] Objects = new Object[maxObjectNum];

このように定数にするといけるみたいです。
("変数で指定する方法"ではないですね、ごめんなさい)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?