1. Back To Blog

.NET interview questions: -Describe operator overloading?

.NET interview questions: -Describe operator overloading?

Operator overloading is a concept of polymorphism where you can redefine operators like +, - , * etc with additional functionalities.

For instance we can redefine the + functionalities to add objects like obj1 + obj2. Below is simple code snippet which redefines + operator.

class SomeClassprivate int someValue;public SomeClass(int val)someValue = val; }public static SomeClass operator +(SomeClass arg1, SomeClass arg2)return new SomeClass(arg1.someValue + arg2.someValue);}}

You can now use the + operator to add objects of type someclass as shown in the below code snippet.

Obj = obj1 = obj2;

Also see the following private constructor video: -




interview questions and answers for .NET  for preparation of real time interviews.

Regards,

Get more from author's blogs for Most asked .NET interview questions
 

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social