How to store multiple types of data in C# using the collection?

Asked 26-Aug-2021
Viewed 1768 times

0

How to store multiple types of data in C# using the collection? using array list in C# programming.


1 Answer


0

Yes, we can store multiple types of data in C# using the collection. System.Collections namespace provides this feature to store multiple types of data in C#. This namespace has some classes to provide this feature.
  1. ArrayList
  2. Stack
  3. Queue
  4. Hashtable
Example 
using System;

using System.Collections;
public class Program
{
 public static void Main()
 {
  ArrayList list=new ArrayList();
  list.Add(45);
  list.Add('Ram');
  list.Add('M');
  list.Add(15.23);
  list.Add(Convert.ToByte(12));
  foreach(var item in list)
  Console.WriteLine('Item : '+item+' Type : '+item.GetType().Name);
 }
}

Output

Item : 45 Type : Int32

Item : Ram Type : String
Item : M Type : Char
Item : 15.23 Type : Double
Item : 12 Type : Byte