title: C# - How to get item from the list with complex type
body: <p>I am new in c# and have a problem with lists.</p>
  
  <p><strong>I have a class Message:</strong></p>
  
  <pre><code>public class Message
  {
      public int MessageId { get; set; }
      public DateTime CreatedDate { get; set; }
      public string Text { get; set; }
      public string Autor { get; set; }
      public string Source { get; set; }
  }
  </code></pre>
  
  <p><strong>and class MessageHandler:</strong></p>
  
  <pre><code>class MessageHandler
  {
      private List&lt;Message&gt; _dummyMessages = new List&lt;Message&gt;()
         {
              new Message(){
                  MessageId = 1,
                  CreatedDate = new DateTime(2014, 5, 27),
                  Text = "Srpska vodoprivreda...",
                  Autor = "Marko Markovic",
                  Source = "Twitter"
  
              },
              new Message(){
                  MessageId = 2,
                  CreatedDate = new DateTime(2014, 5, 27),
                  Text = "Aerodrom Beograd...",
                  Autor = "Zoran Zoric",
                  Source = "B92"
  
              }
          };
  
      public List&lt;Message&gt; GetLatestMessages(int nrMessagesToReturn)
      {
          List&lt;Message&gt; retVal;
  
          retVal = this._dummyMessages.GetRange(0, nrMessagesToReturn);
  
          return retVal;
      }
  
     //todo: Search list _dummyMessages and get Source and
     //check is it equal to "Twitter"
  }
  </code></pre>
  
  <p>My problem is that I dont know how to get Source from <code>List&lt;Message&gt;</code> :( I started like this:</p>
  
  <pre><code>public List&lt;Message&gt; SearchBySource()
  {
      List&lt;Message&gt; retVal;
  
      foreach (Message m in _dummyMessages) 
      {
          //..........
      }
      return retVal;
  }
  </code></pre>
  
  <p>but what to do to get Source from Message?</p>
  
  <p>I want to take Source from Message and then check is it "Twitter", because I want to count all "Twitter" sources from my list...</p>
  
  <p>Sorry for stupid question, and thanks for help!!</p>