How to use var implicit type to create and print a list of ints in c#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int>
            {
                1,
                2,
                3,
                4,
                5
            };

            foreach (int n in list)
                Console.WriteLine(n);
        }
    }
}

/*
run:

1
2
3
4
5

*/

 



answered Jan 5, 2017 by avibootz

Related questions

1 answer 170 views
1 answer 164 views
2 answers 211 views
211 views asked Dec 26, 2016 by avibootz
4 answers 344 views
2 answers 188 views
...