Instead of:
class MyClass
{
private int _value;
public MyClass()
{
_value = OtherClass.StaticInt;
}
}
Favour:
class MyClass
{
private int _value;
public MyClass(int valueForConstruction)
{
_value = valueForConstruction;
}
}
Decouples MyClass
from OtherClass
, even if you do this:
MyClass c = new MyClass(OtherClass.StaticInt);
2
solved Access static property in another class’s non-static constructor in c# [closed]