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 283 views
1 answer 183 views
2 answers 249 views
1 answer 223 views
2 answers 256 views
1 answer 188 views
1 answer 148 views
148 views asked Mar 6, 2023 by avibootz
...