How to print a list values with foreach loop in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);

            foreach (int element in list) {
                Console.WriteLine(element);
            }
        }
    }
}


/*
run:
  
1
2
3
4
 
*/

 



answered Aug 15, 2018 by avibootz
edited Aug 15, 2018 by avibootz

Related questions

2 answers 293 views
1 answer 195 views
2 answers 257 views
1 answer 234 views
2 answers 264 views
1 answer 200 views
1 answer 157 views
157 views asked Mar 6, 2023 by avibootz
...