There's no inbuilt method to achieve that, but you can write custom "helper class":
void Main()
{
Dictionary<string, int> Messagetype = new Dictionary<string, int>();
Messagetype.Add("a", 1);
Messagetype.Add("b", 1);
Messagetype.Add("c", 2);
Messagetype.Add("d", 2);
Messagetype.Add("e", 3);
DataTable dt = HelperClass.ToDataTable(Messagetype);
}
public static class HelperClass
{
public static DataTable ToDataTable(Dictionary<string, int> d)
{
DataTable dt = new DataTable();
dt.Columns.Add("Item1", typeof(string));
dt.Columns.Add("Item2", typeof(int));
var result = d.Select(x=> dt.LoadDataRow(new object[] {x.Key, x.Value}, false));
dt = result.CopyToDataTable();
return dt;
}
}
For further details, please see:
DataTable.LoadDataRow Method (Object[], Boolean) (System.Data)[
^]
Creating a DataTable From a Query (LINQ to DataSet)[
^]
[EDIT]
Bruno, Thank you for your valuable comment!
[/EDIT]