国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實(shí)現(xiàn)Ruby的負(fù)數(shù)索引器

2019-10-29 21:23:38
字體:
供稿:網(wǎng)友

C#實(shí)現(xiàn)Ruby的負(fù)數(shù)索引器

public class InvertibleList<T> : List<T>  {    public new T this[int index]    {      get      {        if (index >= 0) return base[index];        if (Count + index < 0)          throw new IndexOutOfRangeException();        return this[Count + index];      }      set      {        if (index >= 0)          base[index] = value;        else        {          if (Count + index < 0)             throw new IndexOutOfRangeException();          this[Count + index] = value;        }      }    }      }

使用方法:

InvertibleList<string> list=new InvertibleList<string>      {        "1",        "2",        "3",        "4",        "5",      };      list[-2] = "asd";      list.ForEach(Console.WriteLine);

代碼很簡(jiǎn)單,使用也很方便,希望對(duì)大家學(xué)習(xí)C#能夠有所幫助


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到c#教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宝坻区| 南昌市| 历史| 耿马| 当涂县| 抚松县| 绥芬河市| 公主岭市| 永胜县| 永靖县| 德惠市| 吉林市| 尚义县| 来安县| 公安县| 博兴县| 姜堰市| 彭阳县| 胶南市| 东辽县| 东方市| 忻州市| 吉安县| 腾冲县| 吕梁市| 江源县| 大港区| 扬州市| 淮阳县| 丹棱县| 玉溪市| 土默特右旗| 大姚县| 福州市| 玉门市| 蒲江县| 凤阳县| 安溪县| 新化县| 景德镇市| 越西县|