Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please help me! i have a list (ex: List<object> listO = new list<object>), i want to display all the member in this list subtract last member. thank you so much!
Posted

If you use Linq this is quite simple, but it's just as simple just to use a for-loop and iterate over all the Objects in the List.Count - 1.

Here's a Linq solution:
C#
// required
using System.Linq;

// somewhere in your code:
foreach (object theObject in listO.Take(listO .Count - 1))
{
   // do something with each Object here
}
 
Share this answer
 
v2
C#
object lastObj = listO[listO.Count -1];


Pretty easy eh?
 
Share this answer
 
Comments
Ron Beyer 22-Nov-13 21:30pm    
OK, I admit I only read the title and the first half of the first sentence...
alex giulio 22-Nov-13 23:47pm    
oh, hi, actually it very easy, but i..... thank you so much!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900