When trying to use an array as an argument for the string.Format() method, I get the following error:
FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
The code is as follows:
place = new int[] { 1, 2, 3, 4};
infoText.text = string.Format("Player1: {0} \n Player2: {1} \n Player3: {2} \n Player4: {3}", place);
The Array contains four values and the arguments in the String.Format() are also the same.
What causes this error?
(The infoText.text is just a regular String object)
int[]as opposed to astring[]string.Format("Player1: {0} \n Player2: {1} \n Player3: {2} \n Player4: {3}", place[0], place[1], place[2], place[3]);It works as you pass an object relating every {} in stringinfoText.text = string.Join("\n", place.Select((p,i) => $"Player{i+1}: {p}"));