作者s3748679 (冷羽忆尘)
看板C_Sharp
标题Re: [问题] class中存取阵列元素的写法
时间Thu Aug 11 11:39:35 2011
嘿~我也来仿一个..
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
1F:推 horngsh:This is C# Indexer. 08/11 17:11