Home  >  Article  >  Backend Development  >  The difference between methods and functions in C#

The difference between methods and functions in C#

WBOY
WBOYforward
2023-08-23 16:57:021195browse

The difference between methods and functions in C#

In C#, methods and functions are the same.

However, with methods in C#, they are functions that operate on a specified 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.

The following is a simple example showing how to create a method in C#.

Example

class NumberManipulator {
   public int FindMax(int num1, int num2) {
      /* local variable declaration */
      int result;
      if (num1 > num2) {
         result = num1;
      }else {
         result = num2;
      }
      return result;
   }
   ...
}

The above is the detailed content of The difference between methods and functions in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete