Hi,
how i can find the last element of arraylist.

Recommended Answers

All 3 Replies

I don't know C# but I can tell you the logic.

int a[10];

for(i=0;i<a.length;i++);

printf("Last element %d ",a[i-1]);

commented: That is not an array list, also, 0 - 1 = -1... +0

ArrayList is an ordered collection of objects so last element must be Count-1.

ArrayList a = new ArrayList()
            {
                11,22,33,44,55,77
            };

 object last=a[a.Count - 1];

 List<int> b = new List<int>()
            {
                11,22,33,44,55,66,77
            };

 int lastele=b.Last();

Hey Thnaks for the help ...............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.