Created
March 24, 2017 07:10
-
-
Save a5ync/82a67cd96c7a3119cf02dcf999312ecd to your computer and use it in GitHub Desktop.
Average city temperatures in CS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
public class CityTemps | |
{ | |
public string City { get; set; } | |
public string Year { get; set; } | |
public double Temp { get; set; } | |
} | |
static void Main(string[] args) | |
{ | |
var temps = new string[] { | |
"Denver,2011,10", | |
"Denver,2012,20", | |
"Denver,2013,30", | |
"Denver,2014,40", | |
"Vegas,2000,100", | |
"Vegas,2001,98", | |
"Reno,2001,50" }; | |
var list = new List<CityTemps>(); | |
temps.ToList().ForEach(k => | |
{ | |
var segs = k.Split(",".ToCharArray()); | |
list.Add(new CityTemps() | |
{ | |
City = segs[0], | |
Year = segs[1], | |
Temp = Double.Parse(segs[2]) | |
}); | |
}); | |
var p = list.GroupBy(g => g.City) | |
.Select(g => new | |
{ | |
City = g.Key, | |
AvarageTemp = g.Average(pg => pg.Temp) | |
}).OrderBy(o => o.City); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment