我有一个从Button()派生的自定义按钮类:
type Game15Button(position:Point) as button =
inherit Button()
member this.Pozition = position
如何在F#中创建一个Game15Button按钮数组,如下面的C#代码那样?
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++;
}
答案 0 :(得分:3)
let buttons = [
for y in {0..3} do
for x in {0..3} do
yield Game15Button(Point(x, y), Size = Size(50, 50))
]
如果您需要数组,请改用[| ... |]
。