B
Bill Woodruff
I've found it's no problem to insert instances of named delegates as values
into a generic dictionary of the form :
private Dictionary<KeyType, Delegate> myDictionary = new
Dictionary<KeyType, Delegate);
using the standard .Add method of the Dictionary, passing in the name of the
delegate instance for the value.
private void myMethodBody()
{
// do some stuff
}
private delegate void myDelegate();
... in some procedure block :
myDelegate myNewDelegate = myMethodBody;
// assume a valid instance of KeyType
myDictionary.Add(myKeyType, myNewDelegate);
But what I really would like to do would be to somehow insert an anonymous
procedure directly as the value of the key in this dictionary.
Okay, so maybe then dictionary value type is no longer 'Delegate : if not,
what would it be ?
But I keep thinking there may be some clever use of anonymous methods to
eliminate the necessity of having to 'package the method body in delegates
as seen here.
I've been experimenting, but have not yet found anything that works.
thanks,
Bill
into a generic dictionary of the form :
private Dictionary<KeyType, Delegate> myDictionary = new
Dictionary<KeyType, Delegate);
using the standard .Add method of the Dictionary, passing in the name of the
delegate instance for the value.
private void myMethodBody()
{
// do some stuff
}
private delegate void myDelegate();
... in some procedure block :
myDelegate myNewDelegate = myMethodBody;
// assume a valid instance of KeyType
myDictionary.Add(myKeyType, myNewDelegate);
But what I really would like to do would be to somehow insert an anonymous
procedure directly as the value of the key in this dictionary.
Okay, so maybe then dictionary value type is no longer 'Delegate : if not,
what would it be ?
But I keep thinking there may be some clever use of anonymous methods to
eliminate the necessity of having to 'package the method body in delegates
as seen here.
I've been experimenting, but have not yet found anything that works.
thanks,
Bill