I am looking at a code and i see it say
public Action<MainViewModel, MainViewModel> SetView { get; }
Does this indicate that the action SetView
is receiving something? I thought action types were always void?
Also, what what is the (ViewModel.SetView)
portion mean? is that type casting to a SetView
?
SetView = new Action<MainViewModel,MainViewModel>(ViewModel.SetView)
CodePudding user response:
Action
type can only pass parameters. If you want to return a value, then you can use Func<>
.
In your example, SetView
is a property that takes an Action<MainViewModel,MainViewModel>
, which means that the property should be set to a method that accepts 2 MainViewModels as parameters, so something like:
void MyMethod(MainViewModel model1, MainViewModel model2)
{ ... }
Except that yours is just a getter, so I assume it was set in a constructor.