[英]Access objects in a list, perform a foreach using their properties with F#
[英]Array or List of objects in F#
我有一個從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++;
}
let buttons = [
for y in {0..3} do
for x in {0..3} do
yield Game15Button(Point(x, y), Size = Size(50, 50))
]
如果你想要一個數組,請使用[| ... |]
[| ... |]
而不是。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.