Operator Overloading with C# Extension Methods

This is not currently possible, because extension methods must be in static classes, and static classes can’t have operator overloads. But the feature is being discussed for some future release of C#. Mads talked a bit more about implementing it in this video from 2017.

On why it isn’t currently implemented, Mads Torgersen, C# Language PM says:

…for the Orcas release we decided to
take the cautious approach and add
only regular extension methods, as
opposed to extention properties,
events, operators, static methods, etc
etc. Regular extension methods were
what we needed for LINQ, and they had
a syntactically minimal design that
could not be easily mimicked for some
of the other member kinds.

We are becoming increasingly aware
that other kinds of extension members
could be useful, and so we will return
to this issue after Orcas. No
guarantees, though!

Further below in the same article:

I am sorry to report that we will not
be doing this in the next release. We
did take extension members very
seriously in our plans, and spent a
lot of effort trying to get them
right, but in the end we couldn’t get
it smooth enough, and decided to give
way to other interesting features.

This is still on our radar for future
releases. What will help is if we get
a good amount of compelling scenarios
that can help drive the right design.

Leave a Comment

tech