Test Menu

  • Commentary
  • Deals
  • Coupons
Showing posts with label Generic List. Show all posts
Showing posts with label Generic List. Show all posts

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)