473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Overloading or not?

Hi

Just curious on why the C# language does not regard the "return object" as
part of the method signature? Is there any reasonable explaination on why
the following is not allowed?

public DataView GetContacts(string company)
{
....stuff
}

public DataTable GetContacts(string company)
{
...other stuff
}

/Claus
Nov 16 '05 #1
2 1106
Claus Konrad <cl***@whoknows.it> wrote:
Just curious on why the C# language does not regard the "return object" as
part of the method signature? Is there any reasonable explaination on why
the following is not allowed?

public DataView GetContacts(string company)
{
...stuff
}

public DataTable GetContacts(string company)
{
..other stuff
}


Absolutely - it would make code very hard to understand, and in many
cases there'd be ambiguity. For instance:

object o = GetContacts("foo");
or even just
GetContacts("foo");

or

DoSomething(GetContacts("foo"))

where there are overloads for DoSomething() which accept a DataView or
a DataTable.

Yes, you could cast to get the right overload - but it would be a bit
bizarre, IMO.

To me, it doesn't make much sense for what you end up doing with the
return value (if anything) to affect what method is called. It's
information which only becomes relevant *after* the method is called in
every other way. (Compare this with parameters, which are relevant
*before* the method is called.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
There are multiple reasons, but one is that explicit disambiguation would
often be required. Eg, consider if the caller of GetContacts was sticking
the result into an element of an array. The compiler would have to give an
error, at least until you explicitly cast the return before assigning it to
the array element. Once you have to make such casts, you've more than lost
any gain in whatever "elegance" you were hoping for.

Brad Williams

"Claus Konrad" <cl***@whoknows.it> wrote in message
news:#x*************@TK2MSFTNGP11.phx.gbl...
Hi

Just curious on why the C# language does not regard the "return object" as
part of the method signature? Is there any reasonable explaination on why
the following is not allowed?

public DataView GetContacts(string company)
{
...stuff
}

public DataTable GetContacts(string company)
{
..other stuff
}

/Claus

Nov 16 '05 #3

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

Similar topics

17
by: Terje Slettebø | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP...
4
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. ...
5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
39
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any...
45
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
31
by: | last post by:
Hi, Why can I not overload on just the return type? Say for example. public int blah(int x) { }
2
by: brzozo2 | last post by:
Hello, this program might look abit long, but it's pretty simple and easy to follow. What it does is read from a file, outputs the contents to screen, and then writes them to a different file. It...
15
by: lordkain | last post by:
is it possible to do some kind of function overloading in c? and that the return type is different
11
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
10
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.