Create an object in the constructor or at top of the class
问题 which declaration/instantiation is better and WHY ? public class MainWindow { private Test _test; public MainWindow() { _test = new Test(); } } OR public class MainWindow { private Test _test = new Test(); public MainWindow() { } } 回答1: Ask yourself this question: what happens when you add other constructors to MainWindow ? Do you want to then have to remember to invoke other constructors to ensure that _test is correctly initialized? Or is it okay for _test to not be initialized if another