Operator Overloading

  • Definition:

    • Enabling C# mathematical operators to be suitable for your own created classes
  • Example:

        public static ClassName operator+( object1 x, object2 y )
    

        {

  • // new object that contains the result

       return new ClassName(); 
    } 
  • Notes:

At least one argument of an overloaded operator method must be a reference to an object of the class in which the operator is overloaded. This prevents programmers from changing how operators work on simple types

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s