SiteMap  | About    

Multiple data types in an Array

No, we cannot store multiple datatype in an Array, we can store similar datatype only in an Array.

How to Create an Array with different data types

How to store multiple datatypes in an array? interview questions and answers c#

You can create an array with elements of different data types when declare the array as Object. Since System.Object is the base class of all other types, an item in an array of Objects can have a reference to any other type of object.


object[] mixedArray = new object[4]; mixedArray[0]=10; mixedArray[1]="Jack"; mixedArray[2]=true; mixedArray[3]=System.DateTime.Now;

In order to retrieve different data types from an Object array, you can convert an element to the appropriate data type.

int id = int.Parse(mixedArray(0)); DateTime admissionDate = DateTime.Parse(mixedArray(3));


If you want to store different data types in an Array, better use System.Collections.ArrayList.

ArrayList Class

ArrayList Class in .Net framework

ArrayList is basically an alternative to an array. It is one of the most flexible data structure from .Net Framework. It also allow dynamic memory allocation, adding, searching and sorting items in the list. More about.... ArrayList

Array Example

Arrays are using for store similar data types grouping as a single unit. We can access Array elements by its numeric index. The array indexes start at zero. More about.... Array (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.