Foundations
Methods
Methods name reusable work and return a result to the caller.
Methods
Methods.cs
using System;
class Program
{
static int Square(int value)
{
return value * value;
}
static void Main()
{
int side = ;
int area = Square(side);
Console.WriteLine($"side={side}");
Console.WriteLine($"area={area}");
}
}
using System;
class Program
{
static int Square(int value)
{
return value * value;
}
static void Main()
{
int side = ;
int area = Square(side);
Console.WriteLine($"side={side}");
Console.WriteLine($"area={area}");
}
}
using System;
class Program
{
static int Square(int value)
{
return value * value;
}
static void Main()
{
int side = ;
int area = Square(side);
Console.WriteLine($"side={side}");
Console.WriteLine($"area={area}");
}
}
method call
A method call runs the named method and can use the returned value in another expression.