How to clear all items from a List 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>(new int[] {17, 23, 35, 41, 50});

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine($"index[{i}] = {list[i]}");
            }

            Console.WriteLine("total itemss: " + list.Count); 

            list.Clear();

            Console.WriteLine("total itemss: " + list.Count);
        }
    }
}


/*
run:
      
index[0] = 17
index[1] = 23
index[2] = 35
index[3] = 41
index[4] = 50
total items: 5
total items: 0

*/

 



answered Dec 26, 2016 by avibootz

Related questions

1 answer 231 views
1 answer 268 views
1 answer 265 views
1 answer 317 views
1 answer 199 views
1 answer 382 views
1 answer 264 views
...