---
title: "How to implement foreach loop in c# programming?"  
description: "How to implement foreach loop in c# programming?"  
author: "Jonas Stuart"  
published: 2016-09-14  
updated: 2016-09-14  
canonical: https://www.mindstick.com/forum/34176/how-to-implement-foreach-loop-in-c-sharp-programming  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to implement foreach loop in c# programming?

HI Guys\
I am [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in c# [programming language](https://www.mindstick.com/articles/329035/5-most-in-demand-programming-languages-to-consider-for-your-app-development-in-2022) .I want to know that [forEach loop in c#](https://www.mindstick.com/forum/33685/foreach-loop-in-c-sharp) programming.I would really appreciate your help.\
Thanks

## Replies

### Reply by Elena Glibart

The difference between [foreach](https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally) with other looping operations is that foreach is dynamic in nature, whereas other loops are not dynamic. We use foreach concept when we don't aware about the number of entries in the program.

Below is a basic program to learn how to use foreach concept in C# [language](https://www.mindstick.com/startup/28/preply-the-fast-growing-platform-transforming-language-learning). Although we can implement below program by using For or While loop, but this program is helpful to understand how to use foreach concept.

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            int n = 0;             Console.WriteLine("Please enter the number of entry");             n = Convert.ToInt32(Console.ReadLine());             string[] str = new string[n]; // declaring array             for (int i = 0; i < n; i++)            {                Console.WriteLine("Please the entry number {0}", i);                str[i] = Console.ReadLine();            }              foreach (string str1 in str)            {                Console.WriteLine("entry :  " + str1);            }            Console.ReadLine();        }    }}
```


---

Original Source: https://www.mindstick.com/forum/34176/how-to-implement-foreach-loop-in-c-sharp-programming

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
