Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
重複 の可能性: const 配列を宣言する
クラスに const 文字列の配列が必要です。何かのようなもの
public class some_class_t { public const string[] names = new string[4] { "alpha", "beta", "gamma", "delta" }; }
しかし、このコードはエラーを引き起こします:
参照型 'string[]' の定数 'names' は、null でのみ初期化できます。
私は何をすべきか?
readonlyの代わりにconst次のように宣言します。
readonly
const
public readonly string[] names = { "alpha", "beta", "gamma", "delta" };