c# for function code example
Example 1: for loop c#
for(int i = 0; i < 3; i++)
{
Console.WriteLine("Hi");
}
for(int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
for(int i = 5; i <= 8; i++)
{
Console.WriteLine(i);
}
for(int i = 3; i > 0; i--)
{
Console.WriteLine(i);
}
for(;;)
{
}
Example 2: for loop c#
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Value of i: {0}", i);
}
Example 3: function c#
public int AddNumbers(int number1, int number2)
{
int result = number1 + number2;
return result;
}
Example 4: 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);
}