作者tina96391 (AIR)
看板C_Sharp
標題[問題] ArrayList中取得值的問題
時間Fri May 1 22:31:23 2015
寫程式的新手,想問各位大大一個問題><
附上程式一個片段:
private void button2_Click(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
for (int i = 0; i < 10; i++)
{
a = new myCircle(this.CreateGraphics(),
this.ClientSize.Width, this.ClientSize.Height);
list.Add(a);
Thread.Sleep(600);
}
Thread thread1 = new Thread(new ThreadStart(checkDistance));
thread1.Start();
}
如上,myCircle是自己寫的class,裡面有x和y會一直不停變換。
按下button2後螢幕會出現十顆球。
我的問題是,要怎麼從arraylist裡面抓出十顆球個別的x和y位置,謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.168.200.241
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1430490686.A.025.html
推 GoalBased: 請用list 05/01 23:21
→ GoalBased: 或者(myCircle)list[0] 對ArrayList裡面的物件做轉型 05/01 23:22
推 J002: 樓上中肯! 用List<myCircle> 05/02 00:16
→ GoalBased: 補充一下,如果你有看一些C#的文件或書 05/02 00:26
→ GoalBased: 在講到型別的時候都會推薦你用List來代替Array或 05/02 00:26
→ GoalBased: ArrayList,至於為什麼就請你自己去看資料了 05/02 00:27
推 neo5277: 記得是箱子問題? 05/02 02:15