-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayUtil.cs
More file actions
36 lines (33 loc) · 853 Bytes
/
ArrayUtil.cs
File metadata and controls
36 lines (33 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Text;
namespace TestMySpline
{
/// <summary>
/// Utility methods for arrays.
/// </summary>
public static class ArrayUtil
{
/// <summary>
/// Create a string to display the array values.
/// </summary>
/// <param name="array">The array</param>
/// <param name="format">Optional. A string to use to format each value. Must contain the colon, so something like ':0.000'</param>
public static string ToString<T>(T[] array, string format = "")
{
var s = new StringBuilder();
string formatString = "{0" + format + "}";
for (int i = 0; i < array.Length; i++)
{
if (i < array.Length - 1)
{
s.AppendFormat(formatString + ", ", array[i]);
}
else
{
s.AppendFormat(formatString, array[i]);
}
}
return s.ToString();
}
}
}