using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
public int Id { get; set; }
public string Name { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }
public double Salary{ get; set; }
public class ListToDataTable
public static DataTable ToDataTable<T>(List<T> items)
DataTable dataTable = new DataTable(typeof(T).Name);
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
dataTable.Columns.Add(prop.Name);
foreach (T item in items)
var values = new object[Props.Length];
for (int i = 0; i < Props.Length; i++)
values[i] = Props[i].GetValue(item, null);
dataTable.Rows.Add(values);