If you have the following:
public class MyClass {
private static readonly MyObject obj =
new MyObject { parent = listObject[0] };
private static readonly List<MyObject> listObject =
new List<MyObject> { new MyObject() };
}
It will throw a run-time error when MyClass is initialized because when it attempts to initialize obj, listObject is null.
Edit: Is there a way to explicitly specify when each readonly object is initialized (like through an attribute) so listObject is initialized before obj (other than refactoring or reordering the code)? I realize the order determines when each item gets executed, but having the order determine that seems brittle.
I apologize in advance for the simplistic code.