# Add two highest numbers in a data table

Hey,

Can someone show me how to add the highest two numbers in a data table. As an example:

48
21
32
94
14

I would want the sum of 48 and 94

Let me know!

• Using Linq Select the Particular as Array
• Get max number from array
• remove Number from the array
• Get max number from array
• Sum of 2 numbers can be put in Assign

Its Just a try.

@Asanka - pls try below

DT1 = DT.AsEnumerable().OrderBy(Function (row) Convert.ToInt32(row(â€śQuantityâ€ť))).Take(2).CopyToDataTable()

1 Like

This looks like it will work. Do you think you could take me through the code step by step? I want to learn exactly what it is doing. For instance, what does AsEnumerable mean? And the order by function part?

its a linq query â€¦ pls check below link for details
https://www.dotnettricks.com/learn/linq

generic explanation -
IEnumarable -> is a data collectionâ€¦
performing an order on a column -
converting column the data into intergerâ€¦
take is take no of rows (top N records)
finally return as datatable â€¦
DT.AsEnumerable().OrderBy(Function (row) Convert.ToInt32(row(â€śQuantityâ€ť))).Take(2).CopyToDataTable()

Makes sense. So the performing an order on a column part -
I just dont get how its ordering the column. I assume it is ordering it from highest to lowest and then taking the two top numbers. Where in the code is it saying order the DT from highest to lowest? Is it Function??