Task 1 - Creating The Foreachsyntax' Project: File - New - Project Menu Command
Task 1 - Creating The Foreachsyntax' Project: File - New - Project Menu Command
1. Click the Start | Programs | Microsoft Visual Studio | Microsoft Visual Studio menu
command.
2. Click the File | New | Project… menu command.
3. In the New Project dialog select the Visual C# | Windows project type.
4. Select the Console Application template.
5. Provide a name for the new project by entering “ForeachSyntax” in the Name field.
6. Click OK.
Task 2 – Declaring Simple Array and using foreach struct
1. In the Solution Explorer, double click on Program.cs to open the source code.
2. Add array A and some code to used foreach struct in Main of Program class:
static void Main(string[] args)
{
int[] A = { 2, 3, 4, 5, 6, 7, 8, 9 };
foreach (var x in A)
{
Console.WriteLine(x);
}
Console.WriteLine(“Press any key to continue…”);
Console.Readkey();
}
3. Press Ctrl+F5 to build and run the application, displaying the output in a console
window:
4. Press any key to close the console window and terminate the program.