namespace FieldsAndInstanceVariables
{
internal class Program
{
// As the variable is declared in the class and not a method, it's a 'field'
// This can be used throughout the class
static int myResult;
static void Main(string[] args)
{
myResult= Add(5, 5);
Console.WriteLine($"5 + 5 = {myResult}");
myResult= Subtract(5, 5);
Console.WriteLine($"5 - 5 = {myResult}");
}
static int Add(int a, int b)
{
return a + b;
}
static int Subtract(int a, int b)
{
return a - b;
}
}
}
namespace FieldsAndInstanceVariables
{
internal class Program
{
// As the variable is declared in the class and not a method, it's a 'field'
// This can be used throughout the class
static int myResult;
static void Main(string[] args)
{
myResult= Add(5, 5);
Console.WriteLine($"5 + 5 = {myResult}");
myResult= Subtract(5, 5);
Console.WriteLine($"5 - 5 = {myResult}");
}
static int Add(int a, int b)
{
return a + b;
}
static int Subtract(int a, int b)
{
return a - b;
}
}
}