Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Method and Function? [duplicate]

Tags:

c#

I am a beginner in c# and have a keen interest to learn c#, but I am confused. When I asked some one what the difference is between Function and method, he said to me that there is no difference, that they both have the same functionality.
Now I am quite confused and want to know from good developers what methods and functions are?

Are they both the same? If not, then how do I initialize each one??

Is this way to initialize a function correct?

public void UpdateLeaveStatus(EmployeeLeave objUpdateLeaveStatus)

Please provide proper help as I am new.

like image 355
Ammar Asjad Avatar asked Sep 04 '12 07:09

Ammar Asjad


People also ask

What is the difference between method and function?

Method and a function are the same, with different terms. A method is a procedure or function in object-oriented programming. A function is a group of reusable code which can be called anywhere in your program. This eliminates the need for writing the same code again and again.

Are methods and functions the same in C#?

Methods and Functions are the same in C#. However, Methods are used in C# and are functions that operate through a designated class. A method is a group of statements that together perform a task. Every C# program has at least one class with a method named Main.

What is the difference between method and function in C++?

A method is a procedure or function in OOPs Concepts. Whereas, a function is a group of reusable code which can be used anywhere in the program. This helps the need for writing the same code again and again.

What is the difference between method and function in Python?

Functions can be called only by its name, as it is defined independently. But methods can't be called by its name only, we need to invoke the class by a reference of that class in which it is defined, i.e. method is defined within a class and hence they are dependent on that class.


2 Answers

When a function is a part of a class, it's called a method.

C# is an OOP language and doesn't have functions that are declared outside of classes, that's why all functions in C# are actually methods.

Though, beside this formal difference, they are the same...

like image 54
Vitali Kaspler Avatar answered Oct 17 '22 16:10

Vitali Kaspler


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

Method:

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

With respect to Object Oriented programming the term "Method" is used, not functions.

like image 56
Habib Avatar answered Oct 17 '22 14:10

Habib