이미 코드에 함수가있을 때 대리자에 대해 함수 서명을 두 번 선언하지 마십시오. 나는 명백한 무엇인가 놓치고있는 것처럼 느낀다. 그러나 나는 인터넷 검색으로 이것을하는 방법을 발견 할 수 없다.C#에서 기존 함수에서 대리자 서명 선언
public class SomeLibraryV1
{
public int DoSomething(int x, int y);
}
public class SomeLibraryV2
{
public int DoSomething(int x, int y);
}
public class SomeConsumer
{
// Create the delegate by manually declaring the signature again :-(
private delegate int DoSthDelegate(int x, int y);
public void Run(DoSthDelegate aDelegate)
{
aDelegate(1, 2);
}
}
그래서 난 그냥 int fn(int, int)
의 두 번째 선언을 피하면된다 싶은 것.
public class SomeConsumer
{
// Create the delegate from the function signature we already know :-)
public delegate DoSthDelegate(SomeLibrary.DoSomething);
public void Run(DoSthDelegate aDelegate)
{
aDelegate(1, 2);
}
}
이런 일이 두 번 매일 선언을 입력 저를 절약 할뿐만 아니라,하지만 날 두 곳에서 일을 유지하는 데 절약 할 수 DoSomething
변화의 서명이 있어야합니다.
a func? –
OK 그리고 SomeLibrary 선언에서 어떻게 얻습니까? –
무슨 뜻인지 알지만 실행하기 전에이 작업을 수행 할 수있는 방법을 모르겠습니다. 나는 네가 여기 명시해야만한다고 생각해. '''Func <>'''은 당신에게 어떤 타이핑을 저장할 수 있습니다. –