title: How can I find the last element in a List<>?
body: <p>The following is an extract from my code:</p>
  <pre><code>public class AllIntegerIDs 
  {
      public AllIntegerIDs() 
      {            
          m_MessageID = 0;
          m_MessageType = 0;
          m_ClassID = 0;
          m_CategoryID = 0;
          m_MessageText = null;
      }
      
      ~AllIntegerIDs()
      {
      }
  
      public void SetIntegerValues (int messageID, int messagetype,
          int classID, int categoryID)
      {
          this.m_MessageID = messageID;
          this.m_MessageType = messagetype;
          this.m_ClassID = classID;
          this.m_CategoryID = categoryID;
      }
      
      public string m_MessageText;
      public int m_MessageID;
      public int m_MessageType;
      public int m_ClassID;
      public int m_CategoryID;
  }
  </code></pre>
  <p>I am trying to use the following in my <code>main()</code> function code:</p>
  <pre><code>List&lt;AllIntegerIDs&gt; integerList = new List&lt;AllIntegerIDs&gt;();
  
  /* some code here that is ised for following assignments*/
  {
     integerList.Add(new AllIntegerIDs());
     index++;
     integerList[index].m_MessageID = (int)IntegerIDsSubstring[IntOffset];
     integerList[index].m_MessageType = (int)IntegerIDsSubstring[IntOffset + 1];
     integerList[index].m_ClassID = (int)IntegerIDsSubstring[IntOffset + 2];
     integerList[index].m_CategoryID = (int)IntegerIDsSubstring[IntOffset + 3];
     integerList[index].m_MessageText = MessageTextSubstring;
  }
  </code></pre>
  <p>Problem is here: I am trying to print all elements in my List using a for loop:</p>
  <pre><code>for (int cnt3 = 0 ; cnt3 &lt;= integerList.FindLastIndex ; cnt3++) //&lt;----PROBLEM HERE
  {
     Console.WriteLine(&quot;{0}\t{1}\t{2}\t{3}\t{4}\n&quot;, integerList[cnt3].m_MessageID,integerList[cnt3].m_MessageType,integerList[cnt3].m_ClassID,integerList[cnt3].m_CategoryID, integerList[cnt3].m_MessageText);
  }
  </code></pre>
  <p>I want to find the last element so that I equate cnt3 in my for loop and print out all entries in the <code>List</code>. Each element in the list is an object of the class <code>AllIntegerIDs</code> as mentioned above in the code sample. How do I find the last valid entry in the List?</p>
  <p>Should I use something like <code>integerList.Find(integerList[].m_MessageText == null;</code>?</p>
  <p>If I use that it will need an index that will range from 0 to whatever maximum. Means I will have to use another for loop which I do not intend to use. Is there a shorter/better way?</p>