How to store different types of arrays in C#

There are two ways to store the different types of arrays in C#.

  1. Object type is a base type for all the types in .net

    Example

    using System.Collections;

    namespace article

    {

    class programme

    {

    static void main()

    {

    object[] a = new object[3];

    a[0] = 101; //interger

    a[1] = c#; //string

     

    foreachobject obj in a)

    {

    console.writeline(obj); 

    }

    }

    }

    }


  2. Another method is to use the "array list class that present in System.collection namespace".

    ArrayList array = new arraylist();

    array.add(1);

    array.add(abc);

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now