Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
What is The Difference Beetween function and method in asp.net C#4.0
Posted 19-May-11 3:12am
M@n!sh981
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  
v3
Comments
Raja Sekhar S at 28-Jun-13 0:49am
   
Nice Explanation...
+5! For the answer...

--Raj
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
v4
Comments
parmar_punit@yahoo.co.in at 20-May-11 2:02am
   
again 5
SAKryukov at 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 at 21-May-11 9:46am
   
Well explained. My 5 :)
SAKryukov at 21-May-11 21:32pm
   
Thank you, Wonde.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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.
  Permalink  
Comments
SAKryukov at 20-May-11 2:28am
   
Not exactly so. For a whole story, please see my answer.
--SA
Wonde Tadesse at 21-May-11 9:47am
   
Please see --SA answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In object oriented language like C#, we used to call the function as method and a method is a "member function" of a class.
  Permalink  
Comments
SAKryukov at 19-May-11 16:42pm
   
No, you don't know the whole story.
Please see my answer.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
Tarun.K.S at 19-May-11 8:28am
   
I think both are same.
SAKryukov at 19-May-11 16:43pm
   
No, this is not quite correct. Ramalinga, You don't know the whole story.
Please see my answer.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

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!
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 190
1 PIEBALDconsult 150
2 BillWoodruff 148
3 DamithSL 140
4 Jochen Arndt 125
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 20 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100