You can create a property:
int _a;
int a
{
get
{
return _a;
}
set
{
_a = value;
_b = value;
}
}
int _b;
int b
{
get
{
return _b;
}
set
{
_b = value;
}
}
These properties should be created inside a class, but outside a method.
What does this do? When you want to get the value of
a
, the getter will return
_a
, the field. When you want to set the value of
a
, the setter will change the value of both
_a
and
_b
, and
_b
is returned by the getter of
b
.
Read more about properties here:
MSDN - Properties (C# Programming Guide)[
^]