Skip to content

Instantly share code, notes, and snippets.

@tracer8
Last active February 23, 2017 11:48
Show Gist options
  • Save tracer8/f8a56b9056919352d38883cab37c51af to your computer and use it in GitHub Desktop.
Save tracer8/f8a56b9056919352d38883cab37c51af to your computer and use it in GitHub Desktop.
C# Delegate Generic ASK
// IEventParameterBase la 1 interface rỗng
public delegate void EventDelegateGeneric (T eventParam) where T : IEventParameterBase;
private delegate void EventDelegate(IEventParameterBase eventParam);
public EventDelegate myDelegate;
public void AddDelegate(EventDelegateGeneric eventDelegate) where T : IEventParameterBase
{
// Tai sao cai lamda express kia lai co the chuyen duoc tu EventDelegateGeneric thanh EventDelegate?
// và nếu viết thành một hàm riêng thì cái lamda đó sẽ được viết như thế nào?
EventDelegate internalDelegate = (eventParam) => eventDelegate((T)eventParam);
myDelegate += internalDelegate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment