如何为接口定义索引器行为? [英] How to define Indexer behaviour to an Interface?

查看:97
本文介绍了如何为接口定义索引器行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从界面添加索引器行为?

Is it possible to add the indexer behaviour from an interface?

这样的事情:

interface IIndexable<T>
{
   T this[string index];
}


推荐答案

是的,有可能。事实上,你所缺少的只是索引器上的getter / setter。只需按如下方式添加:

Yes, it is possible. In fact, all you're missing is the getter/setter on your indexer. Just add it as follows:

interface IIndexable<T>
{
     T this[string index] {get; set;}
}

这篇关于如何为接口定义索引器行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆