c# function syntax code example
Example 1: How to make a function in C#
public void SayHello(string name)
{
Console.WriteLine("Hello")
}
Console.WriteLine("What is your name?")
string name = Console.ReadLine() ;
SayHello(Adam)
Example 2: c# functions
using System;
public class Program
{
public static void Main()
{
Console.WriteLine(square(4));
Console.WriteLine(cube(4));
}
public static int square(int n)
{
return n * n;
}
public static int cube(int n)
{
return n * n * n;
}
}
Example 3: functions c#
public void SayHello(string name)
{
Console.WriteLine("Hello");
}
public void SayName()
{
Console.WriteLine("What is your name?");
string name = Console.ReadLine();
SayHello(name);
}