I have a question about C # generators and delegation:
First, I describe the general question: I need a set of delegates, these delegates should have a similar form, for example, all my delegates should have the form: take two parameters of the same type and return an int. I think the best way to model these delegates is to use a generic delegate:
public delegate int MyFunctionDel <T> (T a, T b);
But how can I create a MyFunctionDel collection with a different type? I can not declare this:
List<MyFunctionDel <T>> mylist; //Compile error: cannot find type T
And secondly, this is what I'm actually trying to do. What I'm trying to do can be resolved by the above question. But you can give alternative solutions.
I wrote a collection structure: it can store any type of data. But all the data in the structure must be of the same type. Unfortunately, this structure is not common for some historical reason. This structure has a comparison method.
But now I need to provide individual mappings for a specific type. And the behavior I want is: struture uses a configured match if it has one data type, otherwise the original Compare method is used. Here is my demo code:
static class Program { [STAThread] static void Main() { MyStructure s = new MyStructure ();
Any comments, suggestions and ideas are welcome! Thanks guys.
source share