The difference between a method and a function?

I am new to C # and very interested in learning C #, but I'm confused. When I asked someone what the difference is between a function and a method, he told me that there is no difference that they both have the same functionality.
Now I am completely confused and want to know from good developers what methods and functions are there?

Are they both the same? If not, how do I initialize each of them?

Is it possible to properly initialize a function?

public void UpdateLeaveStatus(EmployeeLeave objUpdateLeaveStatus) 

Please provide the right help as I am new.

+43
c #
Sep 04
source share
8 answers

Both are the same, there is no difference in its just another term for the same in C #.

Method :

In object oriented programming method is a subprogram (or procedure or function ) associated with a class.

For object-oriented programming, the term "method" is used, not function.

+35
Sep 04 '12 at 7:50
source share

When a function is part of a class, it calls a method.

C # is an OOP language and does not have functions declared outside of classes, so all functions in C # are actually methods.

Although, in addition to this formal difference, they are the same ...

+38
Sep 04
source share

In C #, they are interchangeable (although a method is the right term) because you cannot write a method without including it in the class. If it did not depend on the class, then this would be a function. Methods are functions that work through an assigned class.

+7
Dec 26
source share

There are no functions in C #. There are methods (typical method: public void UpdateLeaveStatus(EmployeeLeave objUpdateLeaveStatus) ) a link to msdn and functors - a variable of type Func<>

+4
Sep 04
source share

well, in some programming languages โ€‹โ€‹they are called functions that others call it methods, the fact is that they are one and the same. It is an abstract form of expression of a mathematical function:

 f -> f(N:N). 

means its function with values โ€‹โ€‹from natural numbers (just an example). Thus, in addition to the name, this is exactly the same, presenting a block of code containing instructions for solving your purpose.

+3
Sep 04 '12 at 7:52
source share

From the concept of object-oriented programming:

If you have a function that accesses / mutates the fields of your class, it becomes a method. Otherwise, it is a function.

It will not be a crime if you use all the functions of the Java / C ++ classes as methods. The reason is that you directly or indirectly access the properties of the / mutating class. So why aren't all functions in Java / C ++ classes methods?

+3
Nov 04 '12 at 19:52
source share

Both are the same, both are terms that mean encapsulating some code in a unit of work that can be called from elsewhere.

Historically, there may have been a subtle difference when the โ€œmethodโ€ was something that does not return a value, and the โ€œfunctionโ€ that does. in C #, which will look like this:

 public void DoSomething() {} // method public int DoSomethingAndReturnMeANumber(){} // function 

But in fact, I repeat that there really is no difference in the 2 concepts.

+1
Sep 04
source share
Structural programmers know it as a function, whereas in OOPS it is called a method.

But there is no difference between them.

In the old days, methods did not return values โ€‹โ€‹and functions. Now they are both used interchangeably.

+1
04 Sep '12 at 8:20
source share



All Articles