C# ArrayList Class Tutorial with Examples

C# ArrayList Class Tutorial with Examples

Today, We want to share with you C# ArrayList Class Tutorial with Examples.
In this post we will show you ArrayList in C#.Net, hear for .net – ArrayList vs List<> in C# we will give you demo and example for implement.
In this post, we will learn about C# ArrayList – Features and Usage with an example.

ArrayList in C#.Net

In this post,we will learn about ArrayList in C#.Net with an example.

READ :  Laravel INSERT UPDATE DELETE Example Step By Step

Now in this post, I will explain about how to get ArrayList in C#.Net with appropriate example.

ArrayList represents an ordered collection of an object that can be indexed individually. It is an alternative to an array. But, unlike an array, you can add and/or remove items from a list at a specified position using an index and the array resizes itself automatically.

Useful Property

 

Capacity :

It is use to gets or sets the number of elements that the ArrayList can contain.

Count:

It is use to gets the number of elements actually contained in the ArrayList.

IsFixedSize:

It is use to gets a value indicating whether the ArrayList has a fixed size.

READ :  jQuery Multidimensional Array name selector

IsReadOnly:

It is use to gets a value indicating whether the ArrayList is read-only.

Item:

It is use to gets or sets the element at the specified index.

Useful Method

 

public virtual int Add(object value)

This methods adds an object to the end of the ArrayList.

public virtual void AddRange(ICollection c)

This methods adds the elements of an ICollection to the end of the ArrayList.

public virtual void Clear()

This method removes all elements from the ArrayList.

public virtual bool Contains(object item)

This method determines whether an element is in the ArrayList.

Now create Console Application in Visual Studio and write below lines of code in it.

READ :  Laravel Trusting All Proxies & Configuring Trusted Proxies

[php]
using System;
using System.Collections;
using System.Collections.Generic;

namespace ConsoleDemo
{
class Program
{
static void Main(string[] args)
{
ArrayList _NumberList = new ArrayList();

Console.WriteLine(“Adding some Numbers in ArrayList:”);
_NumberList.Add(45);
_NumberList.Add(78);
_NumberList.Add(33);
_NumberList.Add(56);
_NumberList.Add(12);
_NumberList.Add(23);
_NumberList.Add(9);

Console.WriteLine(“Capacity: {0} “, _NumberList.Capacity);
Console.WriteLine(“Count: {0}”, _NumberList.Count);

Console.Write(“Content: “);
foreach (int i in _NumberList)
{
Console.Write(i + ” “);
}

Console.WriteLine();
Console.Write(“Sorted Content: “);
_NumberList.Sort();
foreach (int i in _NumberList)
{
Console.Write(i + ” “);
}
Console.WriteLine();
Console.ReadKey();
}
}
}
[/php]
OutPut:
[php]
Adding some Numbers in ArrayList:
Capacity: 8
Count: 7
Content: 45 78 33 56 12 23 9
Sorted Content: 9 12 23 33 45 56 78
[/php]

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about C# ArrayList Class.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment