InitializerBlock - mehdimo/janett GitHub Wiki
Initializer Block are unnamed blocks of code shared between constructors. Java compiler copies them to each constructor. In C#, we merge initializer blocks to a new method and call this method in every constructor. If class has no constructor, we create a default one.
[Java]
public class Location
{
int x;
int y;
{
x = 0;
}
public void Reset
{
}
{
y = 100;
}
}
[C#]
public class Location
{
int x;
int y;
public Location()
{
InitLocation();
}
public void Reset
{
}
private void InitLocation()
{
x = 0;
y = 100;
}
}