Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
can you tell me what is main difference between method and function ?...
how we identify them ? ...
Thank you.
Posted
Comments
Sebastian T Xavier 16-Jul-12 1:55am    
Poor question
StianSandberg 16-Jul-12 1:59am    
Please explain why Seb..
Sebastian T Xavier 16-Jul-12 2:28am    
In my understanding, this forum is not for clarifying these silly things....

I've seen this discussion a number of times and my conclusion is that this depends on programming language. There are a lot of different explanations for this and I've never sees any crystal clear answer.

See this thread on stackoverflow:
http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function[^]

It has been discussed on codeproject earlier:
difference between method and function[^]

My opinion: A function returns a value while a method don't.. :)
 
Share this answer
 
v3

As I realized, the both of the concepts are same. It's depends on the programming language.


Consider the following code:


C#
int Add(int a, int b)
{
    return a + b;
}

In C# we call Add - a method. But, in C++ we call it a function.

 
Share this answer
 
Comments
Frank Lindecke 18-Jul-12 1:59am    
I would say, that a method belongs to an object and function not.
Therefore in object oriented languages keyword "this" (the "pointer" to the current object instance) provides us a context (the object instance).
So you can access other methods of this object.

A function is just a body of code with parameters and optional return value.
A method is a function with an additional "context".

More details can be found in every book about object oriented languages.

PS. In C++ we might call a method a function, but it is still a method, because we have the pointer to the object.
Shmuel Zang 18-Jul-12 2:59am    
As you wrote, in C++ we call a method , a function. But, it doesn't matter if there is a this parameter or not. For example take the C++ concept "Virtual Function" - The virtual keyword is only for functions that declared within a class and, it's called a function - not a method. For another example take the C# concept "Static Method" - A static method doesn't have the this parameter and, it's still called a method - not a function.

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