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

后端 未结 13 1311
离开以前
离开以前 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 22:14

    In C# 8.0 you can get the last item with ^ operator full explanation

    List<char> list = ...;
    var value = list[^1]; 
    
    // Gets translated to 
    var value = list[list.Count - 1];
    
    0 讨论(0)
提交回复
热议问题