This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generic example | |
public delegate return-type myDelegate(<ParameterList>); | |
// Concrete example | |
public delegate void responseBehaviour(Person borrower); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// matchingMethod1 matches myDelegate delegate | |
public return-type matchingMethod1(<ParameterList>) { ... } | |
// matchingMethod2 matches myDelegate delegate | |
public return-type matchingMethod2(<ParameterList>) { ... } | |
// askPolitely matches responseBehaviour delegate | |
public void askPolitely(Person borrower) { | |
borrower.say("Y-- Excuse me. You-- I believe you have my stapler?"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generic example | |
public void myMethod(myDelegate paramName) { ... } | |
// encapsulate matchingMethod1 in myDelegate and pass into myMethod | |
myMethod(new myDelegate(matchingMethod1)); | |
// alternative syntax for matchingMethod2 | |
myMethod(matchingMethod2); | |
// Concrete example | |
public void borrowStapler(responseBehaviour lateResponse) { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Action declarations | |
public delegate void Action(); | |
public delegate void Action<in T>(T arg); | |
public delegate void Action<in T1, in T2>(T1 arg1, T2 arg2); | |
// ... | |
public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Func declarations | |
public delegate TResult Func<out TResult>(); | |
public delegate TResult Func<in T, out TResult>(T arg); | |
public delegate TResult Func<in T1, in T2, out TResult>(T1 arg1, T2 arg2); | |
... | |
public delegate TResult Func<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16, out TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Predicate declaration | |
public delegate bool Predicate<in T>(T arg); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClientFetcher { | |
public Client Fetch() { ... }; | |
} | |
public class ProjectFetcher{ | |
public Project Fetch() { ... }; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IFetchThings { | |
Client Fetch(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClientFetcher : IFetchThings { | |
public Client Fetch() { ... }; // implements IFetchThings.Fetch() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProjectFetcher : IFetchThings { | |
public Project Fetch() { ... }; // Does not implement IFetchThings.Fetch() as they have differing return types. A Project isn't a Client. | |
} |
OlderNewer