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.
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.
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.
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.
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.
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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With