csharp method
Code Example - csharp method
/* --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;
functions csharp
public void SayHello(string name)
{
Console.WriteLine("Hello");
}
public void SayName()
{
Console.WriteLine("What is your name?");
string name = Console.ReadLine();
SayHello(name);
}