How will you obtain the length of the longest string in every column of a Datatable assuming that every column in of type string using Lambda?

 Posted by Niladri.Biswas on 7/18/2012 | Category: LINQ Interview questions | Views: 7215 | Points: 40

DataTable dt = new DataTable();

var maximumColumnsLengths =
Enumerable.Range(0, dt.Columns.Count)
.Select(col => dt.AsEnumerable()
.Select(row => row[col]).OfType<string>()
.Max(val => val.Length)).ToList();

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response