C#

C#

Made by DeepSource

.ToString on an array does not stringify its contents CS-W1020

Bug risk
Major
Autofix

The general expectation is that the .ToString method return an appropriate string that best represents an entity. However, calling the said method on an array does not stringify its contents. Rather, it returns a string that represents its type. If your intention is to stringify the array, it is suggested that you use other alternatives such as string.Join().

Bad Practice

Console.WriteLine(new int[]{1, 2, 3, 4, 5}.ToString()); // Prints `System.Int32[]`

Recommended

Console.WriteLine(String.Join(", ", new int[]{1, 2, 3, 4, 5})); // Prints `1, 2, 3, 4, 5`

Reference