Articles → .NET → Arraylist in C#

Arraylist in C#






What is an arraylist?





Syntax


ArrayList obj = new ArrayList();



Namespace





Example


using System;
using System.Collections;

namespace Test1 {
	class Program {
		static void Main(string[] args) {
			ArrayList obj = new ArrayList();
			obj.Add("test1");
			obj.Add(1);
			obj.Add(2.03);

			Console.WriteLine("Looping using foreach loop");

			foreach(object o in obj) {
				Console.WriteLine(o);
			}

			Console.WriteLine("Looping using for loop");

			for (int i = 0; i < obj.Count; i++) {
				Console.WriteLine(obj[i]);
			}

			Console.ReadLine();

		}
	}
}











Output




Picture showing output of arraylist in C#

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, December 14, 2016

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250