473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Signatures for Overloads Question

Hello,

Can someone explain to me why the return value is not part of what makes up
the signature of a function?

I would love to be able to overload a function such as:

public overloads function a(x as string, y as string) as DataReader

and

public overloads function a(x as string, y as string) as DataSet

but I find that I cannot do this in vb.net since the signatures are based on
only the passed parameters (at least I couldn't in the net framework 1.0,
and I don't believe it has changed in 1.1)

Do all the .NET languages, (such as c#, etc) all use the same method for
determining the signature for overloading functions?

Thanks!

Jim
Nov 20 '05 #1
4 1653
Hi James,

Can someone explain to me why the return value is not part of what makes up the signature of a function?


That's easy to explain. Let's say you have thwo methods:

public function GetValue() As String
...
end function

public function GetValue() As Integer
....
end function

and in my code, I do the following:

object o = GetValue()

(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a function,
sorry. This affects all .NET languages.

Regards,

--
Frank Eller [.NET MVP]
www.frankeller.de
..NET Developers Group Munich- www.munichdot.net
Nov 20 '05 #2
The other reason why a return value is NOT considered as a part of the
function signature is because you are not obligated to use the return value
of a function i.e. you can just ignore the return value and use a 'Call
FunctionName' statement instead. In such cases, the compiler simply cannot
resolve the overload.

"Frank Eller [MVP]" <we*******@fran keller.de> wrote in message
news:eu******** *****@tk2msftng p13.phx.gbl...
Hi James,

Can someone explain to me why the return value is not part of what makes

up
the signature of a function?


That's easy to explain. Let's say you have thwo methods:

public function GetValue() As String
...
end function

public function GetValue() As Integer
...
end function

and in my code, I do the following:

object o = GetValue()

(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a function,
sorry. This affects all .NET languages.

Regards,

--
Frank Eller [.NET MVP]
www.frankeller.de
.NET Developers Group Munich- www.munichdot.net

Nov 20 '05 #3
Hmm...

Wouldn't it be nice though, if one would simply HAVE to specify a default
overload, and the compiler would resolve the overload by the type the return
value is assigned to...

i.e.:

<SomeAttributeS ayingThisIsTheD efaultOverLoad( )> _
Public Function DoSomething() As String
Public Function DoSomething() As Integer

This way,

Dim i As Integer = DoSomething()

Would cause the Integer overload to be called

Dim s As String = DoSomething()

Would cause the String overload to be called

Dim o As Object = DoSomething()
or
DoSomething()

Would cause the default (in this case String) overload to be called...

Could be something for Framework 2.0 :o)
Danny van Kasteel
"Nice Chap" <Ni******@Plasm aDyne.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
The other reason why a return value is NOT considered as a part of the
function signature is because you are not obligated to use the return value of a function i.e. you can just ignore the return value and use a 'Call
FunctionName' statement instead. In such cases, the compiler simply cannot
resolve the overload.

"Frank Eller [MVP]" <we*******@fran keller.de> wrote in message
news:eu******** *****@tk2msftng p13.phx.gbl...
Hi James,

Can someone explain to me why the return value is not part of what
makes up
the signature of a function?


That's easy to explain. Let's say you have thwo methods:

public function GetValue() As String
...
end function

public function GetValue() As Integer
...
end function

and in my code, I do the following:

object o = GetValue()

(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a function, sorry. This affects all .NET languages.

Regards,

--
Frank Eller [.NET MVP]
www.frankeller.de
.NET Developers Group Munich- www.munichdot.net


Nov 20 '05 #4
Thanks for the explanations!

And, Danny, I like your idea... I wonder if there is a 'wish list' place
where we could post that idea for Framework 2.0 or even 1.2 or 1.1.1?
;)

Jim
"Danny van Kasteel" <da***@dlw.nl > wrote in message
news:1063798148 .659291@cache2. ..
Hmm...

Wouldn't it be nice though, if one would simply HAVE to specify a default
overload, and the compiler would resolve the overload by the type the return value is assigned to...

i.e.:

<SomeAttributeS ayingThisIsTheD efaultOverLoad( )> _
Public Function DoSomething() As String
Public Function DoSomething() As Integer

This way,

Dim i As Integer = DoSomething()

Would cause the Integer overload to be called

Dim s As String = DoSomething()

Would cause the String overload to be called

Dim o As Object = DoSomething()
or
DoSomething()

Would cause the default (in this case String) overload to be called...

Could be something for Framework 2.0 :o)
Danny van Kasteel
"Nice Chap" <Ni******@Plasm aDyne.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
The other reason why a return value is NOT considered as a part of the
function signature is because you are not obligated to use the return

value
of a function i.e. you can just ignore the return value and use a 'Call
FunctionName' statement instead. In such cases, the compiler simply cannot
resolve the overload.

"Frank Eller [MVP]" <we*******@fran keller.de> wrote in message
news:eu******** *****@tk2msftng p13.phx.gbl...
Hi James,
> Can someone explain to me why the return value is not part of what

makes up
> the signature of a function?

That's easy to explain. Let's say you have thwo methods:

public function GetValue() As String
...
end function

public function GetValue() As Integer
...
end function

and in my code, I do the following:

object o = GetValue()

(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a function, sorry. This affects all .NET languages.

Regards,

--
Frank Eller [.NET MVP]
www.frankeller.de
.NET Developers Group Munich- www.munichdot.net



Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2812
by: dickster | last post by:
I notice when moving from VB.NET -> C# that the overloads are different for <XMLRoot(....) > <XMLElement(....) > but in notice the following seems to compile in C#
7
2106
by: Marcos Stefanakopolus | last post by:
So this is ok: class foo { int myMethod(string, int) { ... } int myMethod(string, double) { ... } } But this is not: class foo {
6
11540
by: Matt Frame | last post by:
I have a client that has asked us to get a digital signature certificate and start digitally signing all files we pass between each other. I have heard of the subject and know about the certs but I have no idea how to do something like this with VB.Net. Has anyone done something like this or know where I can find out information how to...
1
1122
by: Troy | last post by:
A developer created a Crystal report in .NET. I added the .RPT file to one of my .NET projects as an existing file. It immediatly reported several errors in the generated .vb file where it created its class and listed the sections as properties but listed some of them twice, returning different ReportDefinition.Sections items... '----------...
4
1350
by: Gary Paris | last post by:
Why would you use an Overloads routine instead of just putting the code in the default routine? Private Overloads Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress Dim isKey As Boolean = e.KeyChar.IsDigit(e.KeyChar) If isKey Then
4
2354
by: jianyi | last post by:
Hi, I am working on an xml project, and I am trying to understand something. if the author needs to sign one xml file, then his manager will counter-sign, and a third witness will sign, can this be achieved in Java xmldsig package? (or any other package?)
12
2379
by: André | last post by:
Hi, i'm learning working with classes. In class "classbase1", i defined an overridable function. In the class "subclass1", i defined the same function with 'Overrides'. In class "classbase2", i defined the same function and in the class "subclass2", i defined the same function with 'Overloads'. Result: i get the same output.
2
6547
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
In the class below, I inherit from Generic.Dictionary so I can override property Item. Item is not overridable, so I used Shadows, and it works as I want. It works equally well if I replace Shadows with Overloads. Question 1 - Which is preferred in a case like this, Shadows or Overloads. Question 2 - The Override clan (Overrides,...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.