Functions in C#
Functions or Methods are an essential part of programming any software, see whenever we code we have to follow a simple principle of DRY: Don't Repeat Yourself because it increases code quality and saves a lot of time and functions/methods are basically a block of code which we can use anytime we want without repeating ourselves.
There are 2 steps to create and use a method and it is to first create the method and then to make the method work we call it.
<access-modifier><return-type>FunctionName(<parameters>) {
// Code
}
Example
public static void printName(string name) {
}
public static int SomeFunction(int n) {
return n;
}
- Access Modifier: It is used to specify function accessibility in the application.
- Return Types: It defines what value can be returned to the function, it can be void, can be float, string, etc.
- Parameters: It is a list of arguments that we can pass to the function during call.
Functions in C#
Functions or Methods are an essential part of programming any software, see whenever we code we have to follow a simple principle of DRY: Don't Repeat Yourself because it increases code quality and saves a lot of time and functions/methods are basically a block of code which we can use anytime we want without repeating ourselves.
There are 2 steps to create and use a method and it is to first create the method and then to make the method work we call it.
<access-modifier><return-type>FunctionName(<parameters>) { // Code }
Example
public static void printName(string name) { // Code }
public static int SomeFunction(int n) { return n; }