Click here to Skip to main content
15,566,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello ,

I dont know whether this question is right or wrong, but i was just asked that how can i prevent overloading in c#. Any ideas on this?
Michael_Davies 24-Aug-15 12:50pm    
Lots of answers from Google...
[no name] 24-Aug-15 13:51pm    
but i am not able to judge which one is right. That's why i posted here for final correct answer.

I dont like this thing on CP. If i post some question here , means a trust that i can get an answer here. I just love this site, but sometimes the comments hurt me..
OriginalGriff 24-Aug-15 14:13pm    
The problem is that it's a "big question", stated as a single line.
Which means that it can't be simply answered - any more than you found exactly what you wanted to know with a simple Google.
Yes, Michael is right - Google does have lots of answers. But the real problem is that you haven't stated clearly what you need to know. And if you have had "comments hurt me" before then they are probably responding to questions that are as vague.

Remember, we can't see your screen, access your HDD, or read your mind - we only get to work on exactly what you tell us; we get no other context to work from. And there are lots of ways to prevent overloading - but we don;t know what kind of situation your homework wants you to think in terms of.

So take a step back and try to think about the problem from someone who knows nothing about what you are trying to do but who may well know the answer if you ask the right question.
One example I do tend to give is "explain it like you are talking to your mother on the phone" - because if she can't understand what chance do we have? :laugh:
Michael_Davies 24-Aug-15 14:15pm    
Do not use Virtual or Override seems to be the answer, maybe the use of Sealed.

Sometimes the questions hurt ...
Philippe Mori 24-Aug-15 14:15pm    
If someone say to Google the answer, it is usually because they tried it and found a lot of answer.

In addition to solution 1 by Sergey Alexandrovich Kryukov[^], i'd suggest to read this: CA1402: Avoid overloads in COM visible interfaces[^]. It might help you to understand what Sergey wanted to tell you.

In a short: you have to go back to basics and read about inheritance[^], polimorphism[^], member overloading[^], etc.
Share this answer
Sergey Alexandrovich Kryukov 24-Aug-15 14:48pm    
Maciej Los 24-Aug-15 15:27pm    
Thank you, Sergey.
You cannot prevent "overloading" by one simple reason: there is nothing to "prevent". It's not a mechanism or anything special, it's just the rule for naming: you can use the same names for different methods provided that it's possible to resolve which method is to be called by the set of parameters. If some name is allowed, you cannot make it prohibited.

(Perhaps you messed up the terminology and meant to say "prevent overriding". Then, on the level of class, you could use sealed.)

Share this answer
Maciej Los 24-Aug-15 14:23pm    
Override, overload seems to be similar ;)
Sergey Alexandrovich Kryukov 24-Aug-15 14:24pm    
Thank you, Maciej.

The similarity of those words (not notions, of course) confused so many developers/students, so I consider the "term" "overload" (but not "override") as one of the worst computing terms in history. In fact, there is no any need for this term (well, maybe "operator overloading" still could be used, but I wish we had a better term). Just allowing to use the same method id does not need any term at all. The language manual can just state that it's not prohibited, without making much buzz about it ("Much Ado About Nothing"). But some explanation of compile-time errors in cases when the resolution of the method is not possible would be still needed.

Maciej Los 24-Aug-15 15:32pm    
I though i understand these terms... but still i'm not sure i'm gettting of English.

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