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

首頁 > 編程 > C# > 正文

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

2020-01-24 01:02:12
字體:
供稿:網(wǎng)友

C#實現(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);

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 金平| 通城县| 习水县| 邢台市| 饶阳县| 商丘市| 图木舒克市| 沂水县| 中牟县| 泸水县| 宜兴市| 福泉市| 正阳县| 鸡东县| 临沧市| 同江市| 绥宁县| 乌兰察布市| 阿城市| 江孜县| 璧山县| 葵青区| 正定县| 连云港市| 清镇市| 泾源县| 法库县| 临海市| 石阡县| 彩票| 抚远县| 靖宇县| 麟游县| 德州市| 浮山县| 阿合奇县| 新巴尔虎左旗| 扶余县| 女性| 桃园县| 潼南县|