using System;
public class Program
{
public static void Main(String[] args)
{
int a = 1;
int b = 2;
int answer = sum(a,b);//calling the method
Console.WriteLine(answer);
}
//sum is a method
static int sum(int a,int b)
{
return a+b;
}
}
Search on YT: Brackeys C# Methods (for a good explaination)
static void myMethod()
{
Console.WriteLine("Hi")
}
/* --Syntax--
[] = Optional
<> = Required
[modifiers] <return type> <identifier>([<parameter type> <parameter identifier>])
{
//Code block
//Return is required if type is not 'void'
return null;
} */
//Example
/*Modifiers Return Type Identifier Parameters, optional, separate with comma*/
public static bool MyFunc (int x, int y)
{
x = x * 2;
return x > y; //Omittable if return type is void
}
//Shortened to return the given expression |Expression body definition|
public static int answerToEverything() => 42;
namespace ConsoleApp21
{
internal class Program
{
static void Main(string[] args)
{
SayHi();
Console.ReadLine();
}
static void SayHi()
{
Console.WriteLine("Hello User");
}
}
} //Must be within internal class curley bracket