I am struggling to understand or see the benefits or difference over one or the other in the following code scenario.
I have a class like this which uses a field of type LoginViewModel _loginViewModel which allows me access to the LoginViewModel's classes fields and methods:
public partial class LoginWindow : Window
{
private readonly LoginViewModel _loginViewModel;
public LoginWindow()
{
InitializeComponent();
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
_loginViewModel = Resources["LoginViewModel"] as LoginViewModel;
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
_loginViewModel.LoginCheck(this);
}
}
What is the difference or benefit on using the above with the following instead? They both achieve the same results.
public partial class LoginWindow : Window
{
private readonly LoginViewModel _loginViewModel = new LoginViewModel();
public LoginWindow()
{
InitializeComponent();
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
_loginViewModel = Resources["LoginViewModel"] as LoginViewModel;
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
_loginViewModel.LoginCheck(this);
}
}