0
조치 사전을 작성한 후 루프에서 실행하려고합니다. This 질문에 도움이되었지만 사전에 작업을 추가 할 때 컴파일 오류가 계속 발생합니다. - No overload for 'Action' matches delegate 'Action'.
사전 작성 및 실행
감사합니다.
Dictionary<string, Action> dActions = new Dictionary<string, Action>();
// do the actions need to be created?
Action<string, int> actSpot = new Action<string, int>(oBSM.Spot);
Action<string, int> actDelta = new Action<string, int>(oBSM.Delta);
dActions["Spot"] = new Action(actSpot);
dActions["Delta"] = new Action(actDelta);
// or add action to dictionary?
dActions.Add("Spot", oBSM.Spot(string BookOrComp, int DP);
dActions.Add("Delta", oBSM.Delta(string BookOrComp, int DP);
foreach (var BookOrComp in ListBookOrComp)
{
foreach (string Key in dActions.Keys)
{
for (int DP = 1; DP <= 21; DP++)
{
dActions[Key]();
}
}
}
업데이트 : 있습니다
1 괄호 : 나는 아직도
Dictionary<string, Action> dActions = new Dictionary<string, Action>();
// create actions
Action<string, int> actSpot = new Action<string, int>(oBSM.Spot);
Action<string, int> actDelta = new Action<string, int>(oBSM.Delta);
dActions["Spot"] = new Action(actSpot); // no overload for Action matches delegate Action
dActions["Delta"] = new Action(actDelta); // ditto
foreach (var BookOrComp in ListBookOrComp)
{
foreach (string Key in dActions.Keys)
{
for (int DP = 1; DP <= 21; DP++)
{
dActions[Key](BookOrComp,DP); // delegate Action does not take 2 arguments
}
}
}
감사합니다. 괄호를 놓치기를 바보입니다. 개체를 만든 다음 사전에 추가하는 데 동의합니다. 나는''dActions [ "Spot"] = new Action (actSpot)''라인에서 이것을 시도했지만 컴파일 에러가 발생했습니다. ''dActions [Key] (BookOrComp, DP);'' – Zeus
Juan, 나는 당신의 답을 따라 갔지만 여전히 컴파일 오류가 발생했다. 나의 업데이트를 보아라. 다른 모습을 보여 주시겠습니까? – Zeus
"dActions"의 간단한 방법입니다.추가 ("Spot", actSpot); dActions.Add ("Delta", actDelta);''작동하는 것 같습니다. 이것은 사전에 동작을 추가하는 올바른 방법입니까? – Zeus