/// <summary> /// Convert debug variable into a readable string. /// </summary> /// <param name="array"></param> /// <returns></returns> public static string DebugVariableToString(Array array, string floatFomat = "{0:0.0000}") { string[] titles = null; if (array.Rank == 3) titles = new[] { "Depth {0}\n" }; // is the element type a floating point type var arrayType = array.GetType().GetElementType(); var isFloat = arrayType == typeof(float) || arrayType == typeof(double); // convert array to string array var strArray = array.ToStringArray(isFloat ? floatFomat : "{0}"); var max = strArray.ToEnumerable().Select(x => ((string)x).Length).Max(); // recursively convert each dimension of the array into a string var str = new StringBuilder((max + 5) * array.Length); DebugVariableToString(str, max + 4, strArray, new int[array.Rank], titles); return str.ToString(); }