Compiler Error CS0230
Type and identifier are both required in a foreach statement
A foreach statement was poorly formed.
The following sample generates CS0230:
C#
// CS0230.cs
class MyClass
{
public static void Main()
{
int[] myarray = new int[3] {1,2,3};
foreach (int in myarray) // CS0230
{
Console.WriteLine(x);
}
}
}
and the sample below presents the same code, but with no CS0230 error:
C#
class MyClass
{
public static void Main()
{
int[] myarray = new int[3] {1,2,3};
foreach (int x in myarray) // Both type (int) and indentifier (x) are specified
{
Console.WriteLine(x);
}
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: