Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Information website that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,111 questions

16,499 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
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
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();
        
        al.Add("c#");
        al.Add("c");
        al.Add("php");
        al.Add("java");
        al.Add("python");

        Console.WriteLine(al.Count);
    }
}

 
 
/*
run:
 
5
 
*/

 




answered Sep 11, 2019 by avibootz
...