Reputation: 31630
How, in C#, do I have a Func
parameter representing a method with this signature?
XmlNode createSection(XmlDocument doc, params XmlNode[] childNodes)
I tried having a parameter of type Func<XmlDocument, params XmlNode[], XmlNode>
but, ooh, ReSharper/Visual Studio 2008 go crazy highlighting that in red.
Update: okay, Googling for 'c# params func' produced no results, but 'c# params delegate' led me to this question. Following Jon Skeet's answer there, it looks like maybe I could create a delegate
, say Foo
, and then instead of having a parameter to my method of type Func<XmlDocument, params XmlNode[], XmlNode>
, I take a parameter of type Foo
.
Upvotes: 12
Views: 7134
Reputation: 31630
Jon Skeet's answer to this other question led me to try the following, which works:
protected delegate XmlNode CreateSection(XmlDocument doc,
params XmlNode[] childNodes);
protected static void createOrUpdateSettingTree(XmlNode rootNode,
XmlDocument doc, CreateSection createSection) { ... }
Upvotes: 12
Reputation: 456322
You can't have params
in a delegate declaration. You can, however, take a single array, which would work for what you need: Func<XmlDocument, XmlNode[], XmlNode>
.
Upvotes: 5