Click here to Skip to main content
15,310,017 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
   
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.......
   
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 :).
Sergey Alexandrovich Kryukov 14-Mar-11 16:34pm
   
CPian? Who's that? ...It happens from time to time, I don't care if the idiot rush to come confirm the assessment your and my opinion on the level of one's intellectual advancement...

By the way, "idiot" is not a "politically correct" term. First, it is in offense against innocent mentally deficient people (http://en.wikipedia.org/wiki/Idiot) who sometimes don't even know how to vote. From the other hand, the terms suggests it's something bad. I suggest the term "a person of alternative mental orientation" :-)

--SA
Manfred Rudolf Bihy 14-Mar-11 16:52pm
   
How about: "a person deviating from standard accepted social and intellectual behaviour".
Naw, that's not a good definition. That would make me an i**ot too. :)
Sergey Alexandrovich Kryukov 14-Mar-11 18:45pm
   
Sorry, no. Your formulation is absolutely positive. What we're looking for should still be with negative connotation. What I suggested in not my idea, and I never came across with anything better, especially with suggestive word "orientation".

One new idea I had is "Syndrome of primitive personality", which cannot serve the purpose because it sounds clinical. I knew about this formulation from a most funny real-life story from legal enforcement practice. The patient was a female under legal charge for extremely rude and aggressive behavior, so as the insanity defense was in order, the doctor put the above diagnosis as the patient had to be legally responsible, yet she really took the doctor with the same aggression and rude behavior, which was probably her "normal" condition... :-)

--SA
Manfred Rudolf Bihy 14-Mar-11 16:53pm
   
Codeproject == CP
CPian a follower or member of CP.
Sergey Alexandrovich Kryukov 14-Mar-11 19:04pm
   
He-he... Thanks!
--SA
Sergey Alexandrovich Kryukov 14-Mar-11 15:19pm
   
I added clarifying Answer, please see.
--SA
Manfred Rudolf Bihy 14-Mar-11 16:15pm
   
Good answer! 5+
sairam.bhat 15-Mar-11 0:12am
   
sir get me some examples pleas
Espen Harlinn 15-Mar-11 11:46am
   
You're right - my 5
sairam.bhat 16-Mar-11 0:04am
   
why down voted for my question?
   
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.
   
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);
}
   

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