Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
1.75/5 (5 votes)
See more:
in C#.net What is the difference between functions and methods?
Posted
Updated 23-Aug-21 13:01pm

Some historical background: in some languages combining classes with non-class (or structure) functions, a term "method" is used to distinguish methods written in a class (or structure where allowed) from other functions and procedures. There is also a tradition (from Algol to Pascal and beyond) to have two distinct key words: "procedure" and "function" a procedure being the equivalent to C/C++ void function.

In .NET all is called method, because all methods are always declared in classes or structures, so the term "function" is considered as a archaism. This is not a big mistake to call a method "function", simply because there is not semantic difference.

Not that this terminology does not touch run-time semantic, that is, it does not matter is the method is static (another term "class method") or not. As to run-time semantic, a static method plays the role of the legacy "non-class" function or procedure.

—SA
 
Share this answer
 
Comments
Espen Harlinn 18-Apr-11 17:41pm    
Nice reply, my 5
Sergey Alexandrovich Kryukov 18-Apr-11 22:14pm    
Thank you, Espen.
--SA
Nish Nishant 18-Apr-11 18:15pm    
Good info here, my 5.
Sergey Alexandrovich Kryukov 18-Apr-11 22:14pm    
Thank you, Nishant.
--SA
They are 2 words for the same thing. You can call them methods or functions - it does not matter.

Note that it's an incorrect idea that a function refers to a global method and a method refers to a class member. I reckon this wrong idea was propagated because Java and C# typically refer to methods and the word function is more typically used by folks from a C++ background.

I reckon it's a little like folder vs directory. The same thing, but younger people usually say folder.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Apr-11 15:20pm    
Correct, my 5.
I added some background, please see my Solution.
--SA
Nish Nishant 18-Apr-11 18:15pm    
Thanks, and will do.
parmar_punit 19-Apr-11 5:17am    
ya may be you are right but in one reference book i read that In c# There is two class member...
one is data member and another is member function...
and in member function there are six member...
-> Constructor
-> Finalizer
-> Property
-> Indexer
-> Methods
-> Function

so, i've asked this question...

Thanks & Regards
Sergey Alexandrovich Kryukov 19-Apr-11 13:04pm    
Sorry, I don't understand, are you asking a question here?
If it's clear, are you going to formall accept this Solution?
Thank you.
--SA
Espen Harlinn 18-Apr-11 17:41pm    
Nice reply, my 5
A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).

All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.
1. It is implicitly passed the object for which it was called
2. It is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data)


IMP :
A function is just a part of code that executes code and can return
something. A method is, in OOP, a function that is bound to a class. As
in C# there are no stand-alone functions, every function in C# is a method
 
Share this answer
 
v5
Comments
BobJanova 18-Apr-11 10:57am    
Not sure why this is downvoted, it seems pretty close to me. A function implies no side effects and a result specified completely by its argument, and therefore in the context of an OO language should always be static. A method uses information from the instance it is a part of, and can modify it or the wider environment.

The thing I disagree on is the optional status of a function's result. A function must return, as it's the only way it can get information out again (although 'return' can be a logical thing, it is imho permissible to 'return' values via ref or out parameters and still call it a function). A piece of code which is not associated with an instance and has side effects (and therefore can decide not to return a value and still be useful) should be called a 'static method' or a 'procedure'.
Sergey Alexandrovich Kryukov 18-Apr-11 15:23pm    
Please see my Answer.
--SA
Nothing, they're basically the same. The only distinction is that in C# a method
is attached to a class. Since C# is OO language, functions dont exists since function is basically a stand alone method(outside of classes).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Apr-11 15:22pm    
I don't know how to evaluate your answer. It is correct and not at the same time. You need to explain the context. In .NET there is nothing which is not "attached" to the class, even a static method is "attached" though not to the instance. It makes sense for other languages, though.

Please see my Solution.
--SA
function and methode Both are same

manoj
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Apr-11 15:18pm    
I described it in a wider context, to explain the origin and different meanings of the terminology, please see my Solution.
--SA
Sergey Alexandrovich Kryukov 18-Apr-11 15:19pm    
I voted 4, not 5 only because you did not care about spelling and capitalization (please don't tell me it's not your native language; it is not mine as well), will happily up-vote.
--SA
There are distinctions between method and function as far as OO programming is concerned.

method - void return Type
- Call by reference
- Not re-useable: this is because it has no return type and the Outputs are
permanent, hence it can only be called by reference.

- unlike an Abstract, it can be implemented without an Object(outside of classes).

Function - value(of a DataType) return Type
- Call by value
- re-useable: this is because it has a return type and variable value hence it
can only be Call by that same value.
- like an Abstract which cannot be implemented alone but within an Object(inside
of classes).

- Williams George (FCA)
 
Share this answer
 
Comments
Richard Deeming 24-Aug-21 3:50am    
This question was solved over ten years ago. Your solution is inaccurate, and adds nothing to the discussion.

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