Re: [問題] indexer的疑問

看板C_Sharp作者 (23)時間16年前 (2010/02/01 18:08), 編輯推噓3(301)
留言4則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《QQ29 (我愛阿蓉)》之銘言: : 再看indexer這個用法 : 書本上和msdn都舉了簡單的範例 : 他們的class中只有一個array 所以他們寫的get和set都是for這個array : 我的疑問是 如果我有兩個array呢? : 我該怎麼分別說我的indexer是for哪一個array... : MSDN最下面好像想講這個但是很奇怪... : http://msdn.microsoft.com/en-us/library/tkyhsw31.aspx : 怎麼會是string型態 : 而且我在我this前面寫上ISomeInterface. compile就不會過... : 我不曉得為什麼 加上ISomeInterface.,是interface的explicit implementation 跟indexer沒關係 那段是在說如果你的class同時實作兩個都有定義indexer的interface 而且indexer的signature一樣,那就必須用explicit implementation : 還是說indexer只適用於 只有一個array在data member的class.... : 才能像她寫的:Indexers allow instances of a class or struct to be indexed just : like arrays. : 不過我覺得一定不是這樣 想不太通 : 請教一下各位 : 謝謝 indexer其實跟property很像,用存取變數的方式使用一個method 只是property只有一個名字,用object.PropertyName存取 而indexer可以多index參數,用object[index1]存取 index的type和數量、回傳的type都是可以自己定的 實際去存取的也不一定要是一個array -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.166.97.5

02/01 20:17, , 1F
對不起@@您一開始說的explicit imp 可否舉個例子@@
02/01 20:17, 1F

02/01 20:18, , 2F
我怎麼寫都會compile出錯 說什麼public 不該這樣寫之類的
02/01 20:18, 2F

02/02 02:34, , 3F
去掉修飾詞一樣可用 http://nopaste.csie.org/ea2f8
02/02 02:34, 3F

02/02 02:54, , 4F
你的interface決定了他的權限
02/02 02:54, 4F
文章代碼(AID): #1BPgWpkK (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1BPgWpkK (C_Sharp)