>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(); >} >>
>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(); >} >Very neat !! And if readability wasn't a factor it could have been just 2 lines for the creation.....