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 8125239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:45:05+00:00 2026-06-06T06:45:05+00:00

Dummy code: public object Addition(object a, object b) { var type = a.GetType(); var

  • 0

Dummy code:

public object Addition(object a, object b)
{
    var type = a.GetType();
    var op = type.GetMethod("op_Addition", BindingFlags.Static | BindingFlags.Public);
    return op.Invoke(null, new object[] { a, b });
}

This method complains with int/float/double,that can’t find these methods(op_Addition).

So how to build a general addition method?

  • 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-06T06:45:08+00:00Added an answer on June 6, 2026 at 6:45 am

    Yes, they’re not custom operators which exist as members like that – there are built-in IL instructions instead.

    (The same is almost true for string concatenation, except there the C# compiler builds a call to string.Concat.)

    If you’re using C# 4 and .NET 4, the simplest approach is to use dynamic typing:

    public dynamic Addition(dynamic x, dynamic y)
    {
        return x + y;
    }
    

    For earlier versions, you’ll need to special-case certain types 🙁

    It’s not clear what your context is, but you may find Marc Gravell’s article on generic operators interesting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem. This is my code: var method = new DynamicMethod(dummy, null, Type.EmptyTypes);
Code: #include <cstdio> class myc { int dummy; public: int si(){return sizeof(*this);} }; class
Consider this code #include <iostream> #include <cstdio> using namespace std; class Dummy { public:
In this code : public class MyClass { private Object innerValue; public Object getInnerValue()
I have the following dummy code: dt<-data.frame(country=letters[1:20],val=rnorm(20),siz=rnorm(20)) qplot(x=country,y=val,data=dt,geom=point,size=siz) Now I want to increase the
Given this code: class base { public: string foo() const; // Want this to
I want to populate the object's properties with some dummy data. Here is my
I have following sample code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd> <html> <head>
Image Dummy = Image.FromFile(image.png); Dummy.Save(image.bmp, ImageFormat.Bmp); what the question says i have these using
I'm using dummy content for a dev site that has about 100 rows or

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.