Ellipsis notation in C#?

六月ゝ 毕业季﹏ 提交于 2019-12-10 12:27:59

问题


Where can I get info about implementing my own methods that have the ellipsis notation,

e.g.

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

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


回答1:


Have a look at the params keyword




回答2:


From https://docs.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");


来源:https://stackoverflow.com/questions/2551054/ellipsis-notation-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!