Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
2.25/5 (4 votes)
See more:
hi
Is it possible to overload static method in c#?

Thanks & Regards
Sairam Bhat
Posted
Updated 6-Jul-21 18:23pm

Just a short clarification on the correct Answer by Pritesh.

Overloading is nothing special (unlike overriding). This is just having the same name to different methods, nothing else. It relies on the ability of the compiler to tell the different methods by number and types of arguments (which is not always possible, but then the compile-time error comes to help).

In this way, static or non-static does make any difference.

—SA
 
Share this answer
 
Comments
Manfred Rudolf Bihy 14-Mar-11 16:16pm    
Good differentiation! 5+
The idiot hasn't yet striked back. (As far as I can tell) :)
Sergey Alexandrovich Kryukov 14-Mar-11 16:26pm    
Thank you.
I'm expecting one to come and confirm your assessment :-)
--SA
Espen Harlinn 15-Mar-11 11:45am    
Fair - my 5
Sergey Alexandrovich Kryukov 15-Mar-11 12:56pm    
Thank you.
--SA
Ya it is possible to Overload
Static methods but
it can't possible to be override it..........
Thanks.......
 
Share this answer
 
v2
Comments
Pritesh Aryan 14-Mar-11 8:19am    
why i am down voted........
is it wrong answer?
Olivier Levrey 14-Mar-11 8:30am    
I upvoted because this answer doesn't deserve a 1 and is actually correct even though OP would need some more explainations. OP probably mixed overloading and overriding. And I think the down-voter did the same!
Pritesh Aryan 14-Mar-11 8:33am    
Thank you so much... Olivier,
Sergey Alexandrovich Kryukov 14-Mar-11 15:02pm    
This is clear why this answer was down-voted: that voter is an idiot. Apparently, there is a good number of those around.
I vote 5, because this is the only good answer so far.
--SA
Manfred Rudolf Bihy 14-Mar-11 16:15pm    
Oh no SA, now you also called some idiot an idiot. I'll now have to keep an eye on you so that fellow CPian won't bomb you with univotes :).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Mar-11 15:07pm    
Yes, I know this article is not about "override". According to the author, "The title was just a trick to provoke your interest". But! The article is pretty bad and not so easy to understand; more importantly, it does not address the Question. OP _explicitly_ asked about "overloading". My diverting from clear answer?
Another question just for you. Do you always read the article you recommend?
I'm sorry, but I suspect you often don't. Please, be more careful...
--SA
Hi

This How to: override static methods [^] will clear all your questions.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Mar-11 15:06pm    
Yes, I know this article is not about "override". According to the author, "The title was just a trick to provoke your interest". But! The article is pretty bad and not so easy to understand; more importantly, it does not address the Question. OP _explicitly_ asked about "overloading". My diverting from clear answer?
--SA
All these "solutions" were anything but.
Yes is not a useful answer even if it's technically correct.
Give examples or don't bother, and sending a link to a bevy of articles is NOT an answer.

When you are overloading to shorten the method call without using default parameters you need to call one of the other overloaded extension methods. This is how it's done.
C#
public static List<DataObject> Search(this List<DataObject> source, string where, string orderBy)
{
    ....
    return result;
}
public static List<DataObject> Search(this List<DataObject> source, string where)
{
    return source.Search(where, string.Empty);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900