I have encountered a very interesting thing in C#. For example, if you try to iterate over an array of integers using foreach statement, you basically can define item's type as char. For reference you can have a look at the code below:
Normally, you write this:
int[] arr = new int[] { 1, 2, 3, 4 };
foreach (int item in arr)
{
Console.WriteLine(item);
}
But also, you can do this:
int[] arr = new int[] { 1, 2, 3, 4 };
foreach (char item in arr)
{
Console.WriteLine(item);
}
The first code will write out all numbers in console. The second piece of code will print whitespaces. I want to know why it is possible to replace int with char inside foreach statement. And then, why whitespaces are getting printed?