http://simpleprogrammer.com/2010/09/24/explaining-what-action-and-func-are/
上面的代码简单的解释了 Action 和 Func。我仍然没有得到 100% 的含义。或者无法使代码为我工作。
public void SteamVegetable(Vegetable vegetable, int timeInMinutes)
{
CookVegetable(vegetable, Steam, timeInMinutes);
}
public void FryVegetable(Vegetable vegetable, int timeInMinutes)
{
CookVegetable(vegetable, Fry, timeInMinutes);
}
public void BakeVegetable(Vegetable vegetable, int timeInMinutes)
{
CookVegetable(vegetable, Bake, timeInMinutes);
}
public void CookVegetable(Vegetable vegetable,
Action<Vegetable, CookingTime> cookingAction,
int timeInMinutes)
{
Clean(vegetable);
cookingAction(vegetable, Minutes.Is(timeInMinutes));
Serve(vegetable);
}
有人可以帮我将代码从蔬菜转换为数字和 Steam --> Addition, Fry --> Multiplication, Bake --> 当两个操作数传递给它时减法。
当我看到代码工作时,我可以更好地理解它。