How can I find the last element in a List<>?

后端 未结 13 1309
离开以前
离开以前 2020-12-12 21:43

The following is an extract from my code:

public class AllIntegerIDs 
{
    public AllIntegerIDs() 
    {            
        m_MessageID = 0;
        m_Messa         


        
13条回答
  •  离开以前
    2020-12-12 21:55

    You can find it by first counting number of elements in the list e.g

    int count = list.Count();
    

    Then you can index the count - 1 to get last element in list e.g

    int lastNumber = list[count - 1];
    

提交回复
热议问题