DataTable newTable = new DataTable(); if (result.Any()) { // Assume all rows have the same structure, use the first to create the columns var rowForColStructure = result.OfType<GLWebService.goldlasso.anyTypeArray1>().First(); // Create the structures with a generic name DataColumn[] columns = rowForColStructure.item.Select((item, index) => new DataColumn(string.Format("Column{0}", index), item.GetType())).ToArray(); // Add the columns to the table newTable.Columns.AddRange(columns); // New rows get added when the query is executed via the ToList var rows = result.OfType<GLWebService.goldlasso.anyTypeArray1>().Select(item => newTable.Rows.Add(item.item)).ToList(); }The items would still be in their original types. If you need it as strings, change it to:
DataTable newTable = new DataTable(); if (result.Any()) { // Assume all rows have the same structure, use the first to create the columns var rowForColStructure = result.OfType<GLWebService.goldlasso.anyTypeArray1>().First(); // Create the structures with a generic name DataColumn[] columns = rowForColStructure.item.Select((item, index) => new DataColumn(string.Format("Column{0}", index), typeof(string))).ToArray(); // Add the columns to the table newTable.Columns.AddRange(columns); // New rows get added when the query is executed via the ToList var rows = result.OfType<GLWebService.goldlasso.anyTypeArray1>().Select(item => newTable.Rows.Add(item.item)).ToList(); }