Seasons.NET

ちょっとした技術ブログです

構造体の配列を初期化するには?

こんな感じでコンストラクタを用意するといいらしい。

 1 private struct cellPair
 2 {
 3     string Cell;
 4     string Text;
 5     int ColorIndex;
 6     int Width;
 7     public cellPair(string _cell, string _text, int _clidx, int _width)
 8     {
 9         Cell = _cell;
10         Text = _text;
11         ColorIndex = _clidx;
12         Width = _width;
13     }
14 };
15 cellPair InfoArray = new cellPair
16 {
17     new cellPair("a","b",10,10),
18     new cellPair("a","b",10,10),
19 };