using extension methods on int

后端 未结 7 1284
难免孤独
难免孤独 2021-02-19 04:10

I\'m reading about extension methods, and monkeying around with them to see how they work, and I tried this:

namespace clunk {
    public static class oog {
             


        
相关标签:
7条回答
  • 2021-02-19 04:55

    Very clever! A nice attempt, but regrettably we did not implement "extension everything", just extension methods.

    We considered implementing extension properties, extension operators, extension events, extension constructors, extension interfaces, you name it, but most of them were not compelling enough to make it into C# 4 or the upcoming version of C#. We got as far as designing a syntax for the sort of thing you mention. We got rather farther on extension properties; we almost got extension properties into C# 4 but it ended up not working out. The sad story is here.

    http://blogs.msdn.com/b/ericlippert/archive/2009/10/05/why-no-extension-properties.aspx

    So, long story short, no such feature, but we'll consider it for hypothetical future releases of the language.

    You can of course make a "ToBool()" extension method on int if you really do like the retro C convention that non-zero-means-true.

    0 讨论(0)
提交回复
热议问题