Using an array as argument for string.Format()

后端 未结 4 1813
甜味超标
甜味超标 2021-01-07 19:13

When trying to use an array as an argument for the string.Format() method, I get the following error:

FormatException: Index (zero based)

4条回答
  •  半阙折子戏
    2021-01-07 19:46

    Quick fix.

    var place = new object[] { 1, 2, 3, 4 };
    

    C# does not support co-variant array conversion from int[] to object[] therefor whole array is considered as object, hence this overload with a single parameter is called.

提交回复
热议问题