Read Last item of ArrayList in C# and VB.Net

SUJAYS
 
on Apr 15, 2021 11:57 PM
732 Views

How to read array list and print the last item of array?

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Adnaan
 
on Apr 16, 2021 03:57 AM

Hi SUJAYS ,

Pls refer below code

C#

protected void Page_Load(object sender, EventArgs e)
{
    ArrayList arrList = new ArrayList();
    arrList.Add(921);
    arrList.Add(DateTime.Now);
    arrList.Add("Mudassar Khan");
    if (arrList.Count > 0)
    {
        Response.Write("Last Item : " + arrList[arrList.Count - 1]);
    }
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim arrList As ArrayList = New ArrayList()
    arrList.Add(921)
    arrList.Add(DateTime.Now)
    arrList.Add("Mudassar Khan")
    If arrList.Count > 0 Then
        Response.Write("Last Item : " & arrList(arrList.Count - 1))
    End If
End Sub