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.

40,026 questions

51,982 answers

573 users

How to use array list (ArrayList) in C#

7 Answers

0 votes
using System;
using System.Collections;
 
class Program
{
    static void Main() {
        ArrayList al = new ArrayList();
        
        al.Add("c#");
        al.Add("c");
        al.Add("java");
        al.Add("php");
        al.Add("python");

        foreach (object item in al) {
           Console.WriteLine(item);
        }
    }
}
 
 
/*
run:
 
c#
c
java
php
python
 
*/

 



answered Sep 11, 2019 by avibootz
edited Sep 5, 2023 by avibootz
0 votes
using System;
using System.Collections;
 
class Program
{
    static void Main() {
        ArrayList al = new ArrayList();
        
        al.Add("c#");
        al.Add("c");
        al.Add("java");
        al.Add("php");
        al.Add("python");

        foreach (object item in al) {
           Console.WriteLine(item);
        }
        
        Console.WriteLine("\n");
        
        al.Insert(0, "c++");
        al.Insert(3, "vb.net");
        
        foreach (object item in al) {
           Console.WriteLine(item);
        }
    }
}

 
 
/*
run:
 
c#
c
java
php
python


c++
c#
c
vb.net
java
php
python
 
*/

 



answered Sep 11, 2019 by avibootz
edited Sep 5, 2023 by avibootz
0 votes
using System;
using System.Collections;
 
class Program
{
    static void Main() {
        ArrayList al = new ArrayList();
        
        al.Add("c#");
        al.Add("c");
        al.Add("java");
        al.Add("php");
        al.Add("python");

        foreach (object item in al) {
          Console.WriteLine(item);
        }
        
        Console.WriteLine("\n");
        
        al.Remove("java");
        
        foreach (object item in al) {
          Console.WriteLine(item);
        }
    }
}

 
 
/*
run:
 
c#
c
java
php
python


c#
c
php
python
 
*/

 



answered Sep 11, 2019 by avibootz
0 votes
using System;
using System.Collections;
 
class Program
{
    static void Main() {
        ArrayList al = new ArrayList();
        
        al.Add("c#");
        al.Add("c");
        al.Add("java");
        al.Add("php");
        al.Add("python");

        foreach (object item in al) {
          Console.WriteLine(item);
        }
        
        Console.WriteLine("\n");
        
        al.RemoveAt(2);
        
        foreach (object item in al) {
          Console.WriteLine(item);
        }
    }
}

 
 
/*
run:
 
c#
c
java
php
python


c#
c
php
python
 
*/

 



answered Sep 11, 2019 by avibootz
0 votes
using System;
using System.Collections;
 
class Program
{
    static void Main() {
        ArrayList al = new ArrayList();
        
        al.Add("c#");
        al.Add("c");
        al.Add("java");
        al.Add("php");
        al.Add("python");

        foreach (object item in al) {
          Console.WriteLine(item);
        }
        
        Console.WriteLine("\n");
        
        al.RemoveRange(1, 3);
        
        foreach (object item in al) {
          Console.WriteLine(item);
        }
    }
}

 
 
/*
run:
 
c#
c
java
php
python


c#
python
 
*/

 



answered Sep 11, 2019 by avibootz
0 votes
using System;
using System.Collections;
 
class Program
{
    static void Main() {
        ArrayList al = new ArrayList();
        
        al.Add("c#");
        al.Add("c");
        al.Add("php");
        al.Add("java");
        al.Add("python");

        foreach (object item in al) {
          Console.WriteLine(item);
        }
        
        Console.WriteLine("\n");
        
        al.Sort();
        
        foreach (object item in al) {
          Console.WriteLine(item);
        }
    }
}

 
 
/*
run:
 
c#
c
php
java
python


c
c#
java
php
python
 
*/

 



answered Sep 11, 2019 by avibootz
0 votes
using System;
using System.Collections;
  
class Program
{
    static void Main() {
        ArrayList al =  new ArrayList{"c#", "c", "php", "java", "python", "vb.net"};

        Console.WriteLine(al.Count);
    }
}
 
  
  
/*
run:
  
6
  
*/

 



answered Sep 11, 2019 by avibootz
edited Dec 22, 2021 by avibootz

Related questions

2 answers 237 views
237 views asked Feb 9, 2017 by avibootz
1 answer 174 views
1 answer 86 views
1 answer 148 views
148 views asked Sep 10, 2020 by avibootz
1 answer 153 views
1 answer 100 views
100 views asked Apr 20, 2020 by avibootz
1 answer 155 views
155 views asked Apr 30, 2017 by avibootz
...