Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge
  • All
  • C#
  • MVC
  • Web API
  • Azure
  • IIS
  • JavaScript
  • Angular
  • Node.js
  • Java
  • Python
  • SQL Server
  • SEO
  • Entrepreneur
  • Productivity

Difference between Array and ArrayList in C#

The following table lists the differences between Array and ArrayList in C#.

ArrayArrayList
Must include System namespace to use array.Must include System.Collections namespace to use ArraList.
Array Declaration & Initialization:
int[] arr = new int[5]
int[] arr = new int[5]{1, 2, 3, 4, 5};
int[] arr = {1, 2, 3, 4, 5};
ArrayList Declaration & Initialization:
ArrayList arList = new ArrayList();
arList.Add(1);
arList.Add("Two");
arList.Add(false);
Array stores a fixed number of elements. The size of an Array must be specified at the time of initialization. ArrayList grows automatically and you don't need to specify the size.
Array is strongly typed. This means that an array can store only specific type of items\elements.ArrayList can store any type of items\elements.
No need to cast elements of an array while retrieving because it is strongly typed and stores a specific type of items only. The items of ArrayList need to be cast to an appropriate data type while retrieving. So, boxing and unboxing happens.
Performs faster than ArrayList because it is strongly typed.Performs slows because of boxging and unboxing.
Use static helper class Array to perform different tasks on the array.ArrayList itself includes various utility methods for various tasks.

Visit Array or ArrayList in the C# tutorials section for more information.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.