Convert Array to ArrayList

In this article I will explain how to Convert Array to ArrayList.
  • 6545

Introduction

In this article I will discuss the conversion from array to arraylist . An Array has similarities to an array. It stores a one-dimensional collection of elements. It can be converted to an arrayList by passing the array as a parameter to the arraylist.

Example

namespace ConsoleApplication2

{

    class Program

    {

        static void Main(string[] args)

        {

            // Create the array

            string[] array = { "one", "two", "three", "four", "five", "six", "seven" };

            Console.WriteLine("Enter the element of the array:");

            for (int i = 0; i < 7; i++)

            {

                Console.WriteLine(array[i]);

            }

            // Convert Array into ArrayList

            ArrayList arrLst = new ArrayList(array);

            Console.WriteLine("The elements in the arraylist that are copied from array:");

            foreach (string s in arrLst)

            {

                Console.WriteLine(s);

            }

        }

    }

}

 

Output

array_to_arraylist.jpg 

 

Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.