Test Menu

  • Commentary
  • Deals
  • Coupons

Nov 29, 2011

Averages with Linq

Here are two different ways to get the average using Linq.  These examples use a generic list of a class that has a Temperature  property:


Dim avgTemperature = (From c In lst Where c.Temperature IsNot Nothing Select c.Temperature).Average()


Dim avgTemperature = From t In lst Where t.Temperature IsNot Nothing Aggregate Temperature In lst Into Average(t.Temperature)

No comments:

Post a Comment