It is not compiling when data type in foreach is string. It is compiling when data type in foreach is char. Problem is highlighted.
using System;
class Program
{
static void Main(string[] args)
{
string checkStr = "Address";
foreach (string c in checkStr)
Console.Write(c);
Console.ReadKey();
}
}
Loading
VulpesPosted Sep 8, 2013, 11:38 AM
When you iterate through a string using foreach, you therefore iterate through its individual chars. This is why the foreach control variable needs to be a char, not a string.
Posted Sep 8, 2013, 11:40 AM