0

Overloading or overriding c#

same method name, same parameters but different return type. what it is called as overloading or overriding.

22nd Oct 2017, 5:50 PM
anu
anu - avatar
6 Answers
+ 11
@anu We can't have the same method signature with different return type as the compiler will be confused to pick the correct method to call. We overload a method by using different parameters and override by implement or redefine it in another class. 😉
23rd Oct 2017, 3:55 AM
Zephyr Koo
Zephyr Koo - avatar
+ 9
@anu You're welcome! 😉 Besides, glad to have a few challenges with you before this, Happy Learning in C#! 👍
23rd Oct 2017, 4:23 AM
Zephyr Koo
Zephyr Koo - avatar
+ 2
It is not overriding because overriding is about changing the body of the method. Theorectically it should be overloading, because its method definition is changed. However. Changing the return type for a overloaded method is not allowed in c#.
22nd Oct 2017, 6:04 PM
sneeze
sneeze - avatar
+ 2
thank you for your time @sneeze @zephykr koo
23rd Oct 2017, 4:11 AM
anu
anu - avatar
+ 1
Correct. If you want to work with different return types in method. You should use the generic type <T>. Or use void as return type and make your current return type a parameter.
22nd Oct 2017, 6:33 PM
sneeze
sneeze - avatar
0
you mean this case won't work right ..! @sneeze
22nd Oct 2017, 6:30 PM
anu
anu - avatar