OneBite.Dev - Coding blog in a bite size

declare a function with single parameter in C#

Code snippet on how to declare a function with single parameter in C#

public int MyFunction(int x)
{
    // The body of the function
    return x * x;
}

This code declares a simple function named “MyFunction” that takes one parameter named “x” (of type int). Inside the function, the code is written such that it returns the square of the value passed in through “x”. In other words, if you call this function with a value of 6, it will return 36. After the code for the body of the function is written, the keyword “return” is used to tell the computer what value to give back to the code that called the function. In this case, the value of “x” is multiplied by itself and then given back to the calling code.

c-sharp