1

我有一个从 Button() 派生的自定义按钮类:

type Game15Button(position:Point) as button =
      inherit Button()
      member this.Pozition = position

如何像以下 C# 代码那样在 F# 中创建 Game15Button 按钮数组?

MyButton[] buttons = new MyButton[16]; 

int i = 0;
for (int y = 0; y < 4; y++)
   for (int x = 0; x < 4; x++){     
      buttons[i] = new MyButton();
      buttons[i].Size = new Size(50, 50);
      buttons[i].Pozition = new Point(x, y);
      i++;
   }
4

1 回答 1

3
let buttons = [
    for y in {0..3} do
    for x in {0..3} do
    yield Game15Button(Point(x, y), Size = Size(50, 50))
]

如果你想要一个数组,请[| ... |]改用。

于 2013-11-02T07:11:46.687 回答