开发者

Ellipsis notation in C#?

开发者 https://www.devze.com 2022-12-25 08:58 出处:网络
Where can I get info about implementing my own methods that have the ellips开发者_高级运维is notation,

Where can I get info about implementing my own methods that have the ellips开发者_高级运维is notation,

e.g.

static void my_printf(char* format, ...) { }

Also is that called ellipsis notation or is there a fancier name?


Have a look at the params keyword


From https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/params:

By using the params keyword, you can specify a method parameter that takes a variable number of arguments.

You can send a comma-separated list of arguments of the type specified in the parameter declaration or an array of arguments of the specified type. You also can send no arguments. If you send no arguments, the length of the params list is zero.

static void MyPrintf(string format, params object[] args) { }

...

MyPrintf(1, 'a', "test");
0

精彩评论

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

关注公众号