title: Populating List<T> within a foreach loop after pattern matching
body: <p>I'm fairly new to C# programming and need some help.</p>
  
  <p>I am trying to assign values I've gathered from a JSON feed to my own type, a class in which I have defined certain fields (properties) to put the JSON elements into, plus elements that are derived from a RegEx pattern matching process. This will then allow me to access the object using LINQ, as I am using a List to hold my objects.</p>
  
  <p>There is a foreach loop in my code that loops for each match that my RegEx method finds. I am only interested in the parts of the JSON feed where there is a match.</p>
  
  <p>So my own defined class is as such:</p>
  
  <pre><code>//simple field definition class
  public class TwitterCollection
  {
      public string origURL { get; set; }
      public string txtDesc { get; set; }
      public string imgURL { get; set; }
      public string userName { get; set; }
      public string createdAt { get; set; }
  }
  </code></pre>
  
  <p>And then I want to populate List in the RegEx Matches loop:</p>
  
  <pre><code>    foreach (Match match in matches)
      {
  
          GroupCollection groups = match.Groups;
          var tc = new List&lt;TwitterCollection&gt;()
          {
              origURL = groups[0].Value.ToString(),
              txtDesc = res.text,
              imgUrl = res.profile_image_url,
              userName = res.from_user_id,
              createdAt = res.created_at,
  
          };
      }
  </code></pre>
  
  <p>The code will then go on to extract and sort the results via Linq to Objects. But compiler won't actually let me create my <code>var tc = new List&lt;TwitterCollection&gt;()</code> because: 'System.Collections.Generic.List' does not contain a definition for 'origURL' ... even though I have defined it. </p>
  
  <p>It does not flag an error if I simply write  <code>new TwitterCollection</code> but then how do I refer to this in my Linq expression later on??</p>
  
  <p>Please help!</p>