C# Method

Last modified: July 11, 2021

Since C# is object-oriented programming, we group a common set of programming lines that perform a task into a method. The structure of a method is like below

<Access Modifier> <Return Type> <Method Name> (Parameter list) { }

An example of method in C# is below. Let focus on the method called sum, we will look into the class on the next chapter. sum method intake two parameters and return the sum (x + y).

public class Calculator { public int sum (int x, int y) { return x + y; } }