score:3

Accepted answer

Just populate a regular DataTable and you can use it from LINQ

using System;
using System.Data;

namespace ConsoleApplication10
{
  class Program
  {
    static void Main(string[] args)
    {
      var dt = new DataTable();
      dt.Columns.Add("Id", typeof(int));
      dt.Columns.Add("Project Name", typeof(string));
      dt.Columns.Add("Project Date", typeof(DateTime));

      for (int i = 0; i < 10; i++)
      {
        var row = dt.NewRow();
        row.ItemArray = new object[] { i, "Title-" + i.ToString(), DateTime.Now.AddDays(i * -1) };
        dt.Rows.Add(row);
      }

      var pp = from p in dt.AsEnumerable()
               where (int)p["Id"] > 2
               select p;

      foreach (var row in pp)
      {
        Console.WriteLine(row["Id"] + "\t" + row["Project Name"] + "\t" + row["Project Date"]); 
      }

      Console.ReadLine();
    }
  }
}

In the code above you can see how to use LINQ to filter out certain records from the DataTable. You'll need to add the System.Data.DataSetExtensions assembly to your references

IEnumerables are readonly so you can't really do it the way you're asking, but what I've presented is the correct way.

score:0

Maybe you misunderstood something. LINQ is a query language with no side-effects. Thus you can't fill up any structure with it. You can only create a query against any existing information and do some kind of transformation or filtering.

Afterwards you can use this query to fill up some element by using foreach(), ToList() or ToArray(), but you cannot directly use LINQ to insert any element into some other object or collection.


Related Query

More Query from same tag