我如何实现这个委托?
操作似乎不支持 params string[] 作为参数,所以我写了
delegate void WriteFn(string s, params string[] ls);
我有这个函数
void blah(WriteFn Write, string fmt, params string[] a)
现在我想编写一个函数,但我似乎无法弄清楚语法。类似于
{
var sw = ...
blah(new WriteFn(s, ls) { sw.write(s, ls); }, fmt, a);
//not what i want to do but close enough. remember sw isnt a param in WriteFn
我该如何写这个?
Action doesnt seem to support params string[] as a param so i wrote
delegate void WriteFn(string s, params string[] ls);
i have this function
void blah(WriteFn Write, string fmt, params string[] a)
Now i would like to write an function but i cant seem to figure the syntax out. It something like
{
var sw = ...
blah(new WriteFn(s, ls) { sw.write(s, ls); }, fmt, a);
//not what i want to do but close enough. remember sw isnt a param in WriteFn
How do i write this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题不清楚。我们是否应该猜测
sw
是一个StreamWriter
?如果是这样,看起来这会起作用:Your question is not clear. Are we suppose to guess that
sw
is aStreamWriter
? If so, it looks like this would work:我认为你不能这样做,因为根据MSDN。
I think you can't do this because variable argument lists is NOT compatible with anonymous methods, according to MSDN.