在c#中是否有以下区别
//syntax 1
private ICommand newWindowCommand;
public ICommand NewWindowCommand
{
get
{
return newWindowCommand = newWindowCommand ?? new MVVM.RelayCommand(...);
}
}
//syntax 2
private ICommand newWindowCommand;
public ICommand NewWindowCommand
{
get
{
return newWindowCommand ?? new MVVM.RelayCommand(...);
}
}
//syntax 3 the usual way
private ICommand newWindowCommand;
public ICommand NewWindowCommand
{
get
{
if (newWindowCommand==null)
{
newWindowCommand = new MVVM.RelayCommand(...);
}
return newWindowCommand;
}
}
在情况 2 中,它是否将 newWindowCommand 设置为已返回的值,或者我是否必须像情况 1 那样分配它?