0
1

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 5 years have passed since last update.

C#で文字列の配列を初期化

Last updated at Posted at 2018-06-25

やられた~
文字の配列を作って初期化した。

memo.rb
	var result = new string[9];
	result.Initialize();

この方法で初期化したら配列の中身がすべてnullだった!
がーん… ""(空文字?)で初期化されるわけじゃないのね…

memo.rb
	var result = ( new string[9] ).Select( s => "" ).ToArray();

	//albireoさま コメントよりコピー
	var result = Enumerable.Repeat("", 9).ToArray();

忘れないようにメモメモ。
調べたらこんな感じでできるのとのこと。(ありがとう~誰となく…

int にするなら、"" の部分を初期化したい数値にすればいいみたいよ。

0
1
2

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?