2014-06-05 2 views
0

이렇게 할 수 있습니까? 현재 내가이 일을 해요 대리인 목록을 가질 수 있습니까?

System.Collections.Generic.Queue<delegate> methods; 

은 ...
public delegate void Method(); 

System.Collections.Generic.Queue<Method> methods; 

그러나 이것은 단지 나에게 위임 서명과 일치 방법을 대기열 할 수 있습니다. 대기열에있는 모든 서명을 가진 메소드를 넣거나 적어도 다른 매개 변수가있는 메소드를 넣을 수 있기를 원합니다. 예를 들어, 다음과 같이 할 수 있습니다.

methods.Enqueue(MethodOne); 
methods.Enqueue(MethodTwo(int parameter)); //This won't work like this, since 'void' will be enqueued instead of the method. 

이와 비슷한 기능이 있습니까?

답변

3

이 가능합니다 :

List<Delegate> list = new List<Delegate>(); 
    list.Add(new Action(() => Console.WriteLine("Hello world"))); 

하지만 람다 식을 직접 작동하지 않는 것 추가.

+0

나는 그것을 던지면 람다 추가가 효과가 있다고 생각합니다. 예를 들어 http://stackoverflow.com/a/411597/56778 –

+0

실제로 람다 식은 직접 대리자가 아닙니다. 이 예에서는 Func 또는 액션을 추가 할 수 있습니다. – Complexity

관련 문제