14
According to the C documentation#:
The method
String.Format
is responsible for converting the value of objects in strings based on the specified formats and inserts them in another character string.
However, I have a doubt regarding the parameters that are passed to him, this method seems to accept an unlimited amount of parameters, I can pass as many parameters as I want, see the example:
class Program
{
static void Main(string[] args)
{
string numeros = string.Format("Numeros: {0}, {1}, {2}.", "Um", "Dois", "Tres");
string nomes = string.Format("Nomes: {0}, {1}, {2}, {3}, {4}, {5}.", "Joao", "Maria", "Junior", "Carvalho", "Leticia", "Silva");
Console.WriteLine(nomes);
Console.WriteLine(numeros);
}
}
In the example the method was invoked with four parameters, the first being the string which will be formatted and the other values that will be inserted in the string, then he was invoked with seven parameters.
My doubts are:
- How this method was defined to have this accepting behavior various parameters?
- The amount of parameters I can pass to it is unlimited?
- It is possible to write methods like this that can accept a indefinite amount of parameters, if yes, how to do?
- And what can I call this practice?
It seems that it is also possible to use
...
or I’m wrong?– Wallace Maxters
@Wallacemaxters is not possible in C#, which is a shame, but it doesn’t make that much difference.
– Maniero