I would like to know If It\'s possible to create a \"one-line\" Linq to retrieve longest string value of specific Datatable column, meaning that all column data (numbers, dates,
You are looking for ArgMax
- a value such that it has max value of some kind of property. Standard Linq doesn't provide ArgMax
but you can implement it via Aggregate
(i.e. get a single value from a sequence):
string maxString = dt
.AsEnumerable()
.Select(row => row[mycolumn].ToString())
.Aggregate((s, a) => a.Length > s.Length ? a : s);