string.Format fails at runtime with array of integers

前端 未结 7 524
囚心锁ツ
囚心锁ツ 2020-12-31 00:03

Consider string.Format() whose parameters are a string and, among others in the overload list, an object[] or many objects.

This statement

相关标签:
7条回答
  • 2020-12-31 01:08

    Short way to make it work (not the most optimal though):

    int[] myInts = new int[] { 8, 9 };
    string[] myStrings = Array.ConvertAll(myInts, x => x.ToString());
    // or using LINQ
    // string[] myStrings = myInts.Select(x => x.ToString()).ToArray();
    bar = string.Format("{0} and {1}", myStrings);
    
    0 讨论(0)
提交回复
热议问题