不支持在C#中的静态索引?不支持、静态、索引

由网友(安稳先生)分享简介:我一直想这几个不同的方式,但我达到了,它不能做的结论。这是我从过去的其他语言享有的语言功能。难道只是我应该只写了吗?I've been trying this a few different ways, but I'm reaching the conclusion that it can't be done. It...

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

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.

阅读全文

相关推荐

最新文章