SoFunction
Updated on 2025-03-07

An example analysis of method with variable number of parameters in C#

This article describes a method with variable parameters in C#. Share it for your reference. The specific methods are as follows:

To achieve variable number of parameters in C#, the key is to use the params keyword. Moreover, the variable parameter can only be the last of all parameters.

Just a simple example:

Copy the codeThe code is as follows:
void ParamsExample(params string[] sz)
{

}
void ParamsExample2(int i,string str,params string[] sz)
{

}
void Main()
{
   ParamsExample("aa","bb","cc");
   ParamsExample2(100,"111","aa","bb","cc","dd");
}

I hope this article will be helpful to everyone's C# programming.