C# - Ways to convert List into Datatable using C# - QA With Experts

PHOTO EMBED

Wed Feb 09 2022 15:29:06 GMT+0000 (Coordinated Universal Time)

Saved by @raajeshn #undefined

/ Create a sequence. 
Item[] items = new Item[] 
{ new Book{Id = 1, Price = 13.50, Genre = "Comedy", Author = "Gustavo Achong"}, 
  new Book{Id = 2, Price = 8.50, Genre = "Drama", Author = "Jessie Zeng"},
  new Movie{Id = 1, Price = 22.99, Genre = "Comedy", Director = "Marissa Barnes"},
  new Movie{Id = 1, Price = 13.40, Genre = "Action", Director = "Emmanuel Fernandez"}};

// load sequence of scalars.
var query = from i in items
             where i.Genre == "Comedy"
             orderby i.Price
             select i;

DataTable table = LinqQueryToDataTable(query);
content_copyCOPY

https://qawithexperts.com/article/c-/ways-to-convert-list-into-datatable-using-c/92