Re: [問題] 紀錄struct內的資料

看板C_Sharp (C#)作者 (迅雷不及掩耳盜鈴)時間16年前 (2010/05/11 11:17), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串5/5 (看更多)
// 前文恕刪 // 雖不是很懂原Po的需求, 不過還是隔空抓藥寫個雛形給原Po public struct Point { public int X { get; set; } public int Y { get; set; } } public class PropertyPoints { private IList<Point> _points; public PropertyPoints(string property) { _points = new List<Point>(); Property = property; } public string Property { get; set; } public IList<Point> Points { get { return _points; } } // 05/12修正 } public class Data { private IDictionary<string, PropertyPoints> _propertyPointsMap; public Data() { _propertyPointsMap = new Dictionary<string, PropertyPoints>(); } public void Add(string property, int x, int y) { if (_propertyPointsMap.ContainsKey(property)) { _propertyPointsMap[property].Points.Add( new Point() { X = x, Y = y } ); } else { PropertyPoints propertyPoints = new PropertyPoints(property); propertyPoints.Points.Add(new Point() { X = x, Y = y }); _propertyPointsMap.Add(property, propertyPoints); } } } // 05/12修正 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.150.76

05/12 14:44, , 1F
可能你要打個注解 不然原po會看不懂
05/12 14:44, 1F
※ 編輯: flamo 來自: 114.24.152.237 (05/12 20:35)

05/12 20:36, , 2F
修正bug
05/12 20:36, 2F
※ 編輯: flamo 來自: 114.24.152.237 (05/12 20:37)
文章代碼(AID): #1BwCmi3i (C_Sharp)
文章代碼(AID): #1BwCmi3i (C_Sharp)