November 1, 2009

Coder Proposes, C# prohibits !!!!! IL –>Internally Laboured

Hey guys, Have a good time. I was digging a little deeper than shallow on Operator overloading in C#  this day, and rather found some of interesting things under the hood.  Coup d'oeil.

Program that overloads + operator and has a member function "op_Addition" that resembles the signature of the operator function.

This program has a Coordinate class, where i try to overload the binary operator + to add the members x1,y1,x2,y2. At this point considering that the member function op_Addition() is not in place, things are axiomatically working fine. After adding op_Addition(), things become messed up, as my code is not compiling.(The intention behind adding the function is to check the IL difference between a normal function and the operator function whose operation is the same.) and i get the following error.


Omigosh !!!. I was dumbfounded. Something is astray behind the scenes, So i had a look into the IL (commenting the new comer op_Addition() to build successfully), and the operator function is translated something like this

.method public hidebysig specialname static class OperatorImpl.Coortinate op_Addition(class OperatorImpl.Coortinate c1, class OperatorImpl.Coortinate c2) cil managed { }

BED TIME !!!! i will continue the story…..

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pocket
Comments powered by Disqus