C#?е???????????????÷?
???????????? ???????[ 2013/6/8 10:33:13 ] ????????
???????????????????????????????????????????????????????????????????????????????д??
????1?????????????
????C#?е???????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????Щ????????????????£?
[???η?] ???????? this[???????? index]
{
get{//???????????}
set{ //????????????}
}
???????η????? public??protected??private??internal??new??virtual??sealed??override?? abstract??extern.
????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????this???????????????????????????????????????????????????????????????????????????????????磺
class Z
{
//??????100??????????????
private long[] arr = new long[100];
//??????????
public long this[int index]
{
get
{ //?????????Χ
if (index < 0 || index >= 100)
{
return 0;
}
else
{
return arr[index];
}
}
set
{
if (!(index < 0 || index >= 100))
{
arr[index] = value;
}
}
}
????2?????????????
???????????????????????????????????????????????????????????????£?
??????????[????]
???????????????????????????????????????????????????磺
Z z=new z();
z[0]=100;
z[1]=101;
Console.WriteLine(z[0]);
???????????????????z??????????????????????е?????????
????C#?в???????????????????????????????磬????????????????????????????????????????????????????????????????????????????????????????????????????????汾??????檔
????example??
class DayCollection
{
string[] days={"Sun"??"Mon"??"Tues"??"Wed"??"Thurs"??"Fri"??"Sat"};
private int GetDay(string testDay)
{
int i=0;
foreach(string day in days)
{
if(day==testDay)
return i;
i++;
}
return -1;
}
public int this[string day]
{
get{return (GetDay(day))}
}
}
static void Main(string[] args)
{
DayCollection week=new DayCollection();
Console.WriteLine("Fri:{0}"??week["Fri"]);
Console.WriteLine("ABC:{0}"??week["ABC"]);
}
?????????Fri:5
????ABC:-1
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11