Sobes.tech
Junior — Middle

Can you explain what is meant by 'method' in programming?

sobes.tech AI

Answer from AI

In programming, a method is a named part of code that performs a specific task and belongs to a class or object. A method can accept input parameters, perform actions, and return a result. In C#, methods are used to organize logic and enable code reuse.

Example of a method in C#:

public class Calculator
{
    public int Add(int a, int b)
    {
        return a + b;
    }
}

Here, Add is a method that takes two numbers and returns their sum.