Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
What is The Difference Beetween function and method in asp.net C#4.0
Posted

In today's time there is no real difference between functions and methods. They are the same thing. The term method and function is very much language dependant. People tend to use the name method for certain languages and function for others.

C++ - "Functions stand alone and methods are members of a class."

C# - "A method is a code block containing a series of statements."
- "Methods are declared within a class or struct by specifying the access level, the return value,
the name of the method, and any method parameters. Method parameters are surrounded by parentheses,
and separated by commas."

VB - "A Method is a procedure built into the class."
"There are two types of methods in VB .NET: those that return a value (Functions) and those that do
not return a value (Sub Procedures)."

C - In C there is no such term as methods. The term, function, is accepted across the board regardless of
whether is returns something or not.

My advice would be to use the term which the language specification uses.
E.g. When programming in c, use the term function for all.
When programming in vb, use methods for the general term and function for those returning an object
and the term sub-procedure for those that does no return an object.
 
Share this answer
 
v3
Comments
Raja Sekhar S 28-Jun-13 0:49am    
Nice Explanation...
+5! For the answer...

--Raj
Historically, in some languages there was a notion (and still is) of functions and procedures; with functions being those returning some objects and procedures returning nothing. In C/C++ both were called functions, and to avoid notion of procedures, the artificial type void was invented. In this way, procedures appeared to be functions but returning void.

In languages like Basic and Pascal there are still functions and procedures (sub (subroutines like in Fortran) in Basic). Later on, in Object Pascal the functions and procedures being the members of some class both got the name of methods. Compare: VMT = Virtual Method Table, in contrast to C++ with vtbl.

Now, Object Pascal and Delphi became a major predecessor of C# and .NET. As in .NET every method can be only a member of a class or structure, all kinds of method are always called methods. As the result type void is used in C# in the same meaning as in C/C++, there is no special need to make difference between functions and procedures.

That's the whole story, to best of my knowledge.

—SA
 
Share this answer
 
v4
Comments
parmar_punit 20-May-11 2:02am    
again 5
Sergey Alexandrovich Kryukov 20-May-11 2:18am    
Thank you.
Listen to a good advice: change your user name, make is without e-mail address, if you don't like spam.
--SA
Wonde Tadesse 21-May-11 9:46am    
Well explained. My 5 :)
Sergey Alexandrovich Kryukov 21-May-11 21:32pm    
Thank you, Wonde.
--SA
In C# function and method are different name for same thing and there is no difference at all. However in language like VB.net these two things are different. Method (also called as sub routine in vb) is block of code which does not have any return type where function is a block of code which has some return type.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-May-11 2:28am    
Not exactly so. For a whole story, please see my answer.
--SA
Wonde Tadesse 21-May-11 9:47am    
Please see --SA answer
In object oriented language like C#, we used to call the function as method and a method is a "member function" of a class.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-May-11 16:42pm    
No, you don't know the whole story.
Please see my answer.
--SA
A function is a small piece of code which will return something.
In methods we want to write a code which will perform some operations.
Methods must be called by creating object of that class.
 
Share this answer
 
Comments
Tarun.K.S 19-May-11 8:28am    
I think both are same.
Sergey Alexandrovich Kryukov 19-May-11 16:43pm    
No, this is not quite correct. Ramalinga, You don't know the whole story.
Please see my answer.
--SA
This is asked so many times.
Google is easy to use, and your teachers should let you use that instead of other resources.

You should also investigate Structures and Functions whilst you are at it!
 
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