Create IEnumerable<T> with one line in LINQ

Pretty straight-forward, but a useful snippet of code nonetheless. 

Given this class:

    public class AggregateContent
    {
 
        public string Title { get; set; }
        public string Description  { get; set; }
      

        public AggregateContent(string Header, string Content)
        {
            Title = Header;
            Description = Content;
        }
    }

You can use line to create an IEnumerable<AggregateContent> like this:

            IEnumerable<AggregateContent> a = 
                LastNNewsItems.Select(p => new AggregateContent(p.NewsTitle, p.HtmlContent));
 
Technorati Tags:

Print | posted @ Friday, February 05, 2010 4:45 PM

Comments on this entry:

Gravatar # re: Create IEnumerable<T> with one line in LINQ
by Adrian at 3/4/2010 12:16 AM

I found your latest posting informative and helpful.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 
Twitter