다음과 같이 선언 된 유형이 주어짐문제 해결 : 여기에 형식 유추가 실패하지 않는 이유는 무엇입니까?
public class EqualityProbe<T>
{
public EqualityProbe(Func<T> functionToGetActualValue, T expectedValue, string probeDescription) {..}
클라이언트 코드 :
// cannot infer bool here
new EqualityProbe(CanConnectToMachine, true, "Probe machine is online")
// compiles fine
new EqualityProbe<bool>(CanConnectToMachine, true, "Probe machine is online")
필자의 생각은 메소드 그룹 (예 : CanConnectToMachine) 또는 익명 메소드 (람다 표현식) .
그러나이 경우 컴파일러가 두 번째 인수
[C# 생성자가 추론 할 수없는 이유는 무엇입니까?] (http://stackoverflow.com/questions/3570167/why-cant-the-c-constructor-infer-type) – AakashM
가능한 복제본 [ 왜 C#은 클래스 생성자에 함축 된 제네릭 형식을 지원하지 않습니까?] (http://stackoverflow.com/questions/45604/why-doesnt-c-sharp-support-implied-generic-types-on-class-constructors) – nawfal