如题,比如List buf=new List(new string[3]{"a","b","c"});
正常使用下标:string temp=buf[0];得出temp="a".
现在想写一个扩展:string temp=buf["a"];得出temp="a".
当然,举得列子可能不合适,目的是想写一个下标的那种扩展,我记得有这种扩展,但是忘记不知道怎么写的了,望高手指点
C#泛型的下标扩展的写法
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
threenewbee 2015-04-02 15:14关注不可以,扩展方法不支持索引器。你只能用自定义的类实现:
class MyList : List
{
public string this[string index]
{
return this.First(x => x == index);
}
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报