B
Bill Woodruff
<
note : this message was sparked in part by comments by David Browne on a
previous thread : "inserting an anonymous method as a value in a generic
dictionary ?" : David had shown the use of 'Delegate as a valid Type
declaration for the Value of a Generic Dictionary.
I am curious as to why I can compile and use this syntax : it seems to me to
violate the requirement that the Value of a Generic Dictionary be a Type
Name.
private delegate void theHandler();
private Dictionary<Control, theHandler> typeDict;
typeDict = new Dictionary<Control, theHandler>();
I now have a dictonary where the Key is of Type Control, and the Value of
the Key can be a named instance of theHandler :
theHandler theHandler1 = new theHandler(delegate {
MessageBox.Show("hello"); });
TreeView treeView1 = new TreeView();
typeDict.Add(treeView1, theHandler1);
typeDict[treeView1].DynamicInvoke();
Or I could can use an anonymous procedure inserted as a Value :
typeDict.Add
(
treeView1,
delegate
{
TreeNode currentNode = tv1.SelectedNode;
MessageBox.Show("treeview" + " " + currentNode.Text);
}
);
note : this message was sparked in part by comments by David Browne on a
previous thread : "inserting an anonymous method as a value in a generic
dictionary ?" : David had shown the use of 'Delegate as a valid Type
declaration for the Value of a Generic Dictionary.
I am curious as to why I can compile and use this syntax : it seems to me to
violate the requirement that the Value of a Generic Dictionary be a Type
Name.
private delegate void theHandler();
private Dictionary<Control, theHandler> typeDict;
typeDict = new Dictionary<Control, theHandler>();
I now have a dictonary where the Key is of Type Control, and the Value of
the Key can be a named instance of theHandler :
theHandler theHandler1 = new theHandler(delegate {
MessageBox.Show("hello"); });
TreeView treeView1 = new TreeView();
typeDict.Add(treeView1, theHandler1);
typeDict[treeView1].DynamicInvoke();
Or I could can use an anonymous procedure inserted as a Value :
typeDict.Add
(
treeView1,
delegate
{
TreeNode currentNode = tv1.SelectedNode;
MessageBox.Show("treeview" + " " + currentNode.Text);
}
);