Is there a way to overload exponents in C#? I know in some languages (can’t name any off the top of my head), ^ is used for exponential functions, but in C++ and C#, ^ is the bitwise XOR operator, which can be overloaded, but this is not what I want to overload. I wan’t to overload the power function or whatever
For example. I know I can do 2^x with (1 << x). So, my second part, is there an exponential operator in C# or do I have to stick with System.Math.Pow(base, exp);
You could create an extension method to act as a shortcut to Math.Pow(), this is actually a vey common thing to do.
perhaps:
So then you can use it like this:
There’s various formats you can play around with when it comes to extension methods. If your goal is brevity, I’m sure you can come up with something you’ll be happy with.