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

Last Reply 26 days ago By Adnaan

Posted 26 days ago

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

You are viewing reply posted by: Adnaan 26 days ago.
Posted 26 days ago

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