params-keyword

Using C#'s XML comment cref attribute with params syntax

99封情书 提交于 2019-11-30 00:28:07
In C#, I am trying to use <see cref="blah"/> to reference a method signature that contains the params keyword. I know this converts the parameter list to an array, but I can't even figure out how to refer to an array in a CREF attribute. I am finding nothing in my searches and no one I know has any idea, either. The compiler is choking on the square brackets. I've tried all kinds of different combinations, using curly braces, using the Array class, but nothing is working. Does anyone know this? jonp The ECMA 334 Standard PDF, Annex E contains a decent overview of XML Documentation comments.

Changing the params modifier in a method override

陌路散爱 提交于 2019-11-29 07:33:53
问题 I'm aware that a params modifier (which turns in one parameter of array type into a so-called "parameter array") is specifically not a part of the method signature. Now consider this example: class Giraffid { public virtual void Eat(int[] leaves) { Console.WriteLine("G"); } } class Okapi : Giraffid { public override void Eat(params int[] leaves) { Console.WriteLine("O"); } } This compiles with no warnings. Then saying: var okapi = new Okapi(); okapi.Eat(2, 4, 6); // will not compile! gives an

Can I use params in Action or Func delegates?

 ̄綄美尐妖づ 提交于 2019-11-27 21:01:24
When I'm trying to use params in an Action delegate... private Action<string, params object[]> WriteToLogCallBack; I received this design time error: Invalid token 'params' in class, struct, or interface member declaration Any help! How about this workaround? private Action<string, object[]> writeToLogCallBack; public void WriteToLogCallBack(string s, params object[] args) { if(writeToLogCallBack!=null) writeToLogCallBack(s,args); } Or you could define your own delegate type: delegate void LogAction(string s, params object[] args); Variadic type parameters are not possible in C#. That's why

Can I use params in Action or Func delegates?

帅比萌擦擦* 提交于 2019-11-26 22:59:54
问题 When I'm trying to use params in an Action delegate... private Action<string, params object[]> WriteToLogCallBack; I received this design time error: Invalid token 'params' in class, struct, or interface member declaration Any help! 回答1: How about this workaround? private Action<string, object[]> writeToLogCallBack; public void WriteToLogCallBack(string s, params object[] args) { if(writeToLogCallBack!=null) writeToLogCallBack(s,args); } Or you could define your own delegate type: delegate