EDIT
It turns out there is SpecialNameAttribute , which allows you to declare "special" functions in C # that will allow you (among other things) to overload the VB power statement:
public class ExponentClass { public double Value { get; set; } [System.Runtime.CompilerServices.SpecialName] public static ExponentClass op_Exponent(ExponentClass o1, ExponentClass o2) { return new ExponentClass { Value = Math.Pow(o1.Value, o2.Value) }; } }
The op_Exponent function in the above class translates VB into the power operator ^ .
Interestingly, the documentation indicates an attribute that is not currently used by the .NET platform ...
- ORIGINAL RESPONSE -
Not. The power ( ^ ) operator Math.Pow() as Math.Pow() , so there is no way to "overload" it in C #.
From LinqPad:
Sub Main Dim i as Integer Dim j as Integer j = Integer.Parse("6") i = (5^j) i.Dump() End Sub
IL:
IL_0001: ldstr "6" IL_0006: call System.Int32.Parse IL_000B: stloc.1 IL_000C: ldc.r8 00 00 00 00 00 00 14 40 IL_0015: ldloc.1 IL_0016: conv.r8 IL_0017: call System.Math.Pow IL_001C: call System.Math.Round IL_0021: conv.ovf.i4 IL_0022: stloc.0 IL_0023: ldloc.0 IL_0024: call LINQPad.Extensions.Dump
D Stanley
source share