Classes and Objects
Fields
Fields store object state that methods and other code can read or update.
Fields
Fields.cs
using System;
class Counter
{
public int Value;
}
class Program
{
static void Main()
{
int start = ;
Counter counter = new Counter();
counter.Value = start;
counter.Value = counter.Value + 1;
Console.WriteLine($"start={start}");
Console.WriteLine($"value={counter.Value}");
}
}
using System;
class Counter
{
public int Value;
}
class Program
{
static void Main()
{
int start = ;
Counter counter = new Counter();
counter.Value = start;
counter.Value = counter.Value + 1;
Console.WriteLine($"start={start}");
Console.WriteLine($"value={counter.Value}");
}
}
using System;
class Counter
{
public int Value;
}
class Program
{
static void Main()
{
int start = ;
Counter counter = new Counter();
counter.Value = start;
counter.Value = counter.Value + 1;
Console.WriteLine($"start={start}");
Console.WriteLine($"value={counter.Value}");
}
}
field
A field is a variable stored inside an object.