Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8796257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:34:53+00:00 2026-06-13T23:34:53+00:00

I am writing a C# class that is exposed to VB.Net. I would like

  • 0

I am writing a C# class that is exposed to VB.Net. I would like to overload the vb.net ^ operator so that I can write:

Dim c as MyClass
Set c = New ...
Dim d as MyClass
Set d = c^2

In C#, the ^ operator is the xor operator and the power operator doesn’t exist. Is there a way I can do this anyway?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:34:54+00:00Added an answer on June 13, 2026 at 11:34 pm

    EDIT

    It turns out there’s a SpecialNameAttribute that lets you declare “special” functions in C# that will allow you (among other things) to overload the VB power operator:

    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 class above gets translated by VB into the ^ power operator.

    Interestingly, the documentation states the Attribute in not currently used by the .NET framework…

    –ORIGINAL ANSWER —

    No. The power (^) operator gets compiled as Math.Pow() so there’s 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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a class that I know that needs a lock, because the
I'm writing a class that returns both a DataTable and a IEnumerable. I cannot
I'm writing a class that extends a UIScrollView to display a large tiled image,
I am writing a class that inherits from IHttpHandler for script and css combining.
I am writing a class that inherits from IHttpHandler for script and css combining.
I apologize if this is a duplicate. I am writing a class that needs
I'm writing a factory class that should be able to return singleton instances of
first of all, a preface: I'm writing a java class that creates temporary tables
I'm writing a class in C++ that I cannot debug by using F5. The
I have a Runnable class that I'm writing. Inside of it, I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.