Answer the question
In order to leave comments, you need to log in
Is it possible to create a dictionary of delegates returning a List?
Please tell me:
There is a generic class
There is a delegate in it
And there is a dictionaryclass MyClass<T> where T : class
private delegate List<T> TDelegate();
_dctCahceActions = new Dictionary<string, TDelegate>();
_dctCahceActions.Add("x", (() => { return Method1(); }));
_dctCahceActions.Add("y", (() => { return Method2(); }));
...
List<T> res = _dctCahceActions["x"].Invoke();
Answer the question
In order to leave comments, you need to log in
List implies that the type of the contents of the sheets is the same - type T, if objects from methods can be cast to it, then everything should be compiled.
using System;
using System.Collections.Generic;
public class MyClass<T> where T : class
{
private Dictionary<string, Func<List<T>>> functions = new Dictionary<string, Func<List<T>>>();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question