No, method overloading does not support with different
return type in C#/VB.NET. If the signature is same (data type and order of arguments) and
return type is different we will get error in C# or VB.In C# dev,we will get the error after building the
project but in case VB.NET we will get the error beforing building the project.
Below is the piece of code to understand easily.
|
public
int add(int
a,int b)
{
return a+b;
}
public string add(int a, int b)
{
return (a + b).ToString();
}
|
|
C# Complile Error as “ ‘Class_Name' already defines a member called 'add'
with the same parameter types”
|
|
Function add(ByRef a As Integer, ByVal b As Integer) As Integer
Return a + b
End
Function
Function
add(ByRef a As
Integer, ByVal
b As Integer)
As Integer
Return a + b
End
Function
|
|
VB.NET Complile error as 'Public Function add(ByRef a As Integer, b As Integer) As Integer' and 'Public Function add(ByRef a As Integer, b As Integer) As String' cannot overload each other because they differ only by return types.
|
0 Comments:
Post a Comment