In C# you can do this:
foo = string.Format(\"{0} {1} {2} {3} ...\", \"aa\", \"bb\", \"cc\" ...);
This method Format()
accepts in
public static void TestStrings(params string[] stringsList)
{
foreach (string s in stringsList){ }
// your logic here
}
function void MyFunction(string format, params object[] parameters) {
}
Instad of object[] you can use any type your like. The params argument always has to be the last in the line.
A few notes.
Params needs to be marked on an array type, like string[] or object[].
The parameter marked w/ params has to be the last argument of your method. Foo(string input1, object[] items) for example.
use the params keyword. For example
static void Main(params string[] args)
{
foreach (string arg in args)
{
Console.WriteLine(arg);
}
}
You can achieve this by using the params keyword.
Little example:
public void AddItems(params string[] items)
{
foreach (string item in items)
{
// Do Your Magic
}
}
Use the params keyword. Usage:
public void DoSomething(int someValue, params string[] values)
{
foreach (string value in values)
Console.WriteLine(value);
}
The parameter that uses the params keyword always comes at the end.