Answer: DataTable dt = new DataTable();
var maxLength = dt.AsEnumerable()
.SelectMany(r => r.ItemArray.OfType<string>())
.Max(i => i.Length);
First cast the Datatable to System.Collections.Generic.IEnumerable<T> object by using the AsEnumerable() extension method,then using the SelectMany extension method
to find out the items in the ItemArray whose type is string and finally figuring out the max length of the records.
Asked In: Many Interviews |
Alert Moderator