I have a custom button class derived from Button():
type Game15Button(position:Point) as button =
inherit Button()
member this.Pozition = position
How can I create an array of Game15Button buttons in F# as the following C# code does?
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++;
}
let buttons = [
for y in {0..3} do
for x in {0..3} do
yield Game15Button(Point(x, y), Size = Size(50, 50))
]
If you want an array, use [| ... |]
[| ... |]
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.