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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 15, 2013, 1:45 PM
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.
Terrance CPosted Oct 15, 2013, 12:59 PM