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.
You can now use the + operator to add objects of type someclass as shown in the below code snippet.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHyWRBvtXPR8p8pCJTtwQD1qzz40HxViu4em1dsxZmW_D8CKT4u-_5e7ynA2FYgdqYczjdC6Lw2dZ-awq5Pwbo2LLONQbFBseZANiy-9DJauSBtqGOWR4TAwsSOFO_aYUqeWznPUQzog/s400/1.JPG)
Dotnet interview questions and answers for preparation of real time interviews.
Regards,
Get more from author’s blogs for Most asked .NET interview questions
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 SomeClass { private 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: -
Dotnet interview questions and answers for preparation of real time interviews.
Regards,
Get more from author’s blogs for Most asked .NET interview questions
No comments:
Post a Comment