开发者

How do i implement this delegate?

开发者 https://www.devze.com 2022-12-21 14:22 出处:网络
Action doesnt seem to support params string[] as a param so i wrote delegate void WriteFn(string s, params string[] ls);

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 = 开发者_JAVA技巧...
    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?


Your question is not clear. Are we suppose to guess that sw is a StreamWriter? If so, it looks like this would work:

blah((s, ls) => sw.Write(s, ls), fmt, a);


I think you can't do this because variable argument lists is NOT compatible with anonymous methods, according to MSDN.

0

精彩评论

暂无评论...
验证码 换一张
取 消