Title: Example of Generic Delegate?
Tags: c#;generics;generic-programming
Question: Generic classes can declared with generic delegates as shown below but this is unfortunatelly metadata. I can not find full example:
public abstract class Expression
public static Expression<TDelegate&gt; Lambda<TDelegate&gt;(Expression body, bool tailCall, IEnumerable<ParameterExpression&gt; parameters);
in here TDelegate is a Func<>. Can you write a generic class example which uses generic delegate? I could not find an example like that.


Here is another answer: Generic parameters wouldn't help much when constraining delegate types. There's no practical use case for this unless you want to pass a delegate type using a generic argument instead of using regular typeof keyword or Object.GetType method:
public void DoStuff<TDelegate&gt;()
// vs.
public void DoStuff(Type delegateType);
Delegates aren't classes and they don't support inheritance and other features available to classes and interfaces. What you can do is constraining delegate's generic parameters.
For example, you want a Func<T&gt; to constrain that T is IWhatever:
public void DoStuff<T&gt;(Func<T&gt; func) where T : IWhatever

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:09/13/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><generics><generic-programming>', 'Title': 'Example of Generic Delegate?', 'ViewCount': 585, 'id': 32548308, 'user_AboutMe': None, 'user_AccountId': 4988809.0, 'user_DisplayName': 'Yusuf Sipahi', 'user_Reputation': 53.0, 'user_Views': 13.0, 'user_id': 4011653.0}}