Here is my simple piece of code of a Console Application..
int[] a= {1,2,3,4};
char[] b= {'a','b','c'};
Console.WriteLine(a);
Console.WriteLine(b);
Result:
System.Int32[]
abc
When printing, why it is displaying 'System.Int32[]'?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Terrance C25 reputationPosted Oct 15, 2013, 8:59 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 15, 2013, 9:45 AM EDT
http://msdn.microsoft.com/en-us/library/System.Console.WriteLine.aspx
Console.WriteLine(a) invokes the overload which takes an 'object' parameter, as there is no better alternative. This overload applies the ToString() method to the object parameter which in this case simply prints the name of the actual type which is System.Int32[].
However, Console.WriteLine(b) invokes the overload which takes a char[] parameter, which is obviously the best fit. This overload writes the individual chars of the array, one after the other, to the console and therefore prints 'abc' in this case.