Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, I know definations and little bit examples on those. But which purpose we can use the overloading and overriding methods . in my application i am not used of those things. My intension, i will use of those things, but when use of those things, i don't know.
Could you please any one help me .
Posted
Updated 23-Jul-12 21:09pm
v3
Comments
CH Guravaiah 24-Jul-12 2:32am    
can solve my problem any one.
bbirajdar 24-Jul-12 2:46am    
If you had understood the concepts of Overloading and Overriding, you would not have posted this question here.. First study these concepts and you will come to know when to use them...

Your question is like asking 'when to use aeroplane and when to use a ship'..
CH Guravaiah 24-Jul-12 3:02am    
If you understand my question give me example and otherwise leave it yar. If i know why i am asking question. every one doesn't know every thing yar.
bbirajdar 24-Jul-12 3:15am    
We don't do spoon feeding and homework in this forum..Did you read the rules before posting the question? .You need to show your efforts first..Have you googled for this question? There are thousands of examples on this .. click here
Member 10653129 18-Mar-14 7:00am    
u please read rule number 3..

Overloading is the process of defining a number of methods with the same name and return type, but which has different parameters. For example, you might want a method that returns the file content based on the string path:
C#
public string GetFileContent(string path)
   {
   return File.ReadAllText(path);
   }
But you might also find it helpful to define a method which uses a FileInfo:
C#
public string GetFileContent(FileInfo fi)
   {
   return GetFileContent(fi.FullName);
   }
GetFileContent is an overloaded method - it has different versions and which is called depends on teh paramatyers you supply. In the Bad Old Days we would have had to define two differently named methods:
GetFileContentFromPath
GetFileContentFromFileInformation
And then try to remember which were available, and took what parameters!

Overriding is more complex: it is the process of creating a method that sits on top of an existing method in a base class, and which will be called instead of the base class method when it it called. This allows you to have two different derived classes, which both override the same base class method to do class specific actions. When you call the method on an object derived from the base class, the framework works out which method it should call, and class the "highest" override in the list.

You have probably used this quite a bit without noticing it: ToString is very often overridden to provide a human readable version of the class. The default object definition of ToString prints the class name, but when it it overridden it prints the content.
 
Share this answer
 
how we nwill use revers method in array
 
Share this answer
 
i think method overloading also reduce memory space.
 
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