Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipsis notation in C#?

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?

like image 750
y2k Avatar asked Mar 31 '10 07:03

y2k


2 Answers

Have a look at the params keyword

like image 137
Pieter Germishuys Avatar answered Oct 24 '22 12:10

Pieter Germishuys


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");
like image 37
Darin Dimitrov Avatar answered Oct 24 '22 14:10

Darin Dimitrov