Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,940 questions

51,877 answers

573 users

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 131 views
1 answer 147 views
1 answer 127 views
1 answer 191 views
1 answer 115 views
1 answer 222 views
1 answer 140 views
...