Re: [問題] class中存取陣列元素的寫法

看板C_Sharp (C#)作者 (冷羽憶塵)時間14年前 (2011/08/11 11:39), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/6 (看更多)
嘿~我也來仿一個.. class IntList { private List<int> itemList = new List<int>(); public int this[int index] { get { return itemList[index]; } set { itemList[index] = value; } } } ※ 引述《K273 (minus)》之銘言: : class myClass{ : private List<int> itemList = new List<int>(); : public int[] item{ : get { : return itemList.ToArray(); : } : set { : itemList = new List<int>(value); : } : } : } : ※ 引述《BYoYB (BYoYB)》之銘言: : : 各位前輩好,小弟是新接觸C#的新手,有個笨問題請教 : : 如果我有一個class : : Class myClass{ : : Int sn; : : Int[] item = New Int[5]; : : } : : 要存取sn的Get,Set寫成 : : Get{Return sn;} : : Set{this.sn = Value;} : : 我的問題是item的Get, Set要怎麼寫呢? : : 謝謝各位的幫忙 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.164.78.122

08/11 17:11, , 1F
This is C# Indexer.
08/11 17:11, 1F
文章代碼(AID): #1EGqxvpC (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1EGqxvpC (C_Sharp)