1

I would like to get a column of Ages with the values of each row to calculate the Mode. enter image description here

Here is my code:

int[] ages = ?

 var mode = ages.GroupBy(n => n).
           OrderByDescending(g => g.Count()).
           Select(g => g.Key).FirstOrDefault();

My problem is I cant get a lambda expression on grid holding the column of values.

Xdrone
  • 781
  • 1
  • 11
  • 21

1 Answers1

2

You can try something like (if we name you table Person, as I don't know its name) :

List<int> listAges = new List<int>();
// Here db is your DataContext.
listAges = db.Person.OrderByDescending(p => p.Age).Select(p => p.Age).ToList();

Now, in the list named listAges, you have all ages from you table ordered by their age (descending). And if you prefer working on an array, use :

int[] ages = listAges.ToArray();
faflo10
  • 386
  • 5
  • 13