我试图弄清楚之间有什么区别:
public partial class TestWindow : Window
{
object obj = new object();
public TestWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
}
和:
public partial class TestWindow : Window
{
object obj;
public TestWindow()
{
InitializeComponent();
obj = new object();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
}
和:
public partial class TestWindow : Window
{
object obj;
public TestWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
obj = new object();
}
}
看起来它们的行为都相同,我想知道它们之间是否有任何重要区别,或者选择其中一个只是“最佳实践”。提前致谢