不支持在C#中的静态索引? [英] Are static indexers not supported in C#?

查看:259
本文介绍了不支持在C#中的静态索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想这几个不同的方式,但我达到了,它不能做的结论。这是我从过去的其他语言享有的语言功能。难道只是我应该只写了吗?

I've been trying this a few different ways, but I'm reaching the conclusion that it can't be done. It's a language feature I've enjoyed from other languages in the past. Is it just something I should just write off?

推荐答案

没有,静态索引器不支持在C#。不像其他的答案,但是,我怎么看也很容易被点有他们。试想一下:

No, static indexers aren't supported in C#. Unlike other answers, however, I see how there could easily be point in having them. Consider:

Encoding x = Encoding[28591]; // Equivalent to Encoding.GetEncoding(28591)
Encoding y = Encoding["Foo"]; // Equivalent to Encoding.GetEncoding("Foo")

这将是相对很少用,我怀疑,但我认为这是奇怪的是,它的禁止 - 它给不对称性没有特别的原因,据我所见

It would be relatively rarely used, I suspect, but I think it's odd that it's prohibited - it gives asymmetry for no particular reason as far as I can see.

这篇关于不支持在C#中的静态索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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