The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Is there a method behind the madness?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Michael Mello

Posts: 100
Nickname: knarf
Registered: May, 2004

Michael Mello is .NET Web Developer
Is there a method behind the madness? Posted: Jun 8, 2004 6:00 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Michael Mello.
Original Post: Is there a method behind the madness?
Feed Title: melloblog
Feed URL: http://www.thauvin.net/errorpage.htm?aspxerrorpath=/Default.aspx
Feed Description: .NET and Everything After.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Michael Mello
Latest Posts From melloblog

Advertisement
I had a discussion about Method Overloading today, and it seems that the definition and examples available are sometimes lacking, which leads to some confusion.  

It seems that every example on the internet, and inside .NET books that I've come across, always show examples of Method Overloading with different parameters, but never with different modifiers or return types.  The following is a vanilla example of Method Overloading that you might see:


void DisplayResult(string result)
{
//do something
}

void DisplayResult(int result)
{
//do something
}



Of course this code is perfectly fine, but what about different modifiers and return types?  Even though I have trouble finding examples, this is perfectly legal?

Note: The modifier (in this case 'static') is used in only one of the methods.



public static int SweetMethod()
{
//do something
}

public int SweetMethod(int x)
{
//do something
}



?and so is this:

Note: The return types are different in this example. (int and string)



public int SweetMethod()
{
//do something
}

public string SweetMethod(int x)
{
//do something
}



Is the possibility of such a situation so far out in left field that most authors avoid it, or are these implementations of Method Overloading just, "Bad Practice"?

Read: Is there a method behind the madness?

Topic: Update on Telerik r.a.d.editor MCMS edition Previous Topic   Next Topic Topic: .NET Nightly 158

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use