作者tree581 (talltree)
看板C_Sharp
標題如何共用參數
時間Fri Nov 9 19:18:11 2018
當參數已有值,如何在其他class共用?
class main
{
a aa= new a();
aa.i=1
write(aa.s); //這個如何=tt
}
class a
{
public int i{get;set;}
public string s{get;set;}
}
class b
{
a aa=new a();
write(aa.i); // 這個如何能=1
aa.s="tt";
}
請教大大
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.104.212.0
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_Sharp/M.1541762293.A.42D.html
1F:→ testPtt: static 11/09 22:44
2F:→ tree581: 若thread的話static好像會影響,有其他方法嗎 11/10 08:58
3F:推 s4300026: 那就封鎖吧 mutex 11/10 12:17
4F:推 Litfal: 共用沒處理好,不管是不是用static,都有多執行緒問題啊 11/10 12:20
5F:→ smmoon: class a{ public int i{get;set;} public a() { i =1; } } 11/12 14:00
6F:→ smmoon: 喔 你是要共用a ,忽略上面我說的,把 a aa = new a()放到 11/12 14:04
7F:→ smmoon: class main上面 11/12 14:04
8F:→ annies5: class b: a, class main { b aa = new b(); } 11/12 14:58
9F:→ annies5: 使用繼承方式去做 11/12 14:59