how to define a function in C# code example
Example 1: 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 2: function in c#
using System;
public class Program
{
static void function(){
Console.WriteLine("I am a function!");
}
public static void Main()
{
function();
}
}
Example 3: 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 4: c# funtion
public int AddNumbers(int number1, int number2){ int result = number1 + number2; if(result > 10) { return result; } return 0;}
Example 5: function c#
public int AddNumbers(int number1, int number2)
{
int result = number1 + number2;
return result;
}
Example 6: how to define a function in c#
void functionName(int parameter) {
}
functionName(Aninteger)