Combining multiple sequences into 1 object
What is the correct way to iterate through several sequences/list etc., and combine them respectively in an object. For example, I have a list of teams, and two different lists of stats. I would like to combine the two list of stats with the respective team in the list of teams and that to a class. Hope this makes since. Thanks in advance.
VulpesPosted Feb 4, 2012, 3:41 PM
VulpesPosted Feb 18, 2012, 6:48 AM
RichPosted Feb 17, 2012, 9:10 PM
VulpesPosted Feb 15, 2012, 5:05 AM
A problem with writing an article about something like this is that you need to have a basic grasp of LINQ in order to be able to understand it and I'm not sure that many C# developers do.
Anyway, thanks for the idea, and I'll add it to the list :)
RichPosted Feb 14, 2012, 7:27 PM
VulpesPosted Feb 14, 2012, 10:27 AM
RichPosted Feb 13, 2012, 6:57 PM
Spread = g.Average(at => Math.Abs((decimal)at.awayScore - (decimal)at.homeScore))
VulpesPosted Feb 13, 2012, 6:40 PM
RichPosted Feb 13, 2012, 5:33 PM
RichPosted Feb 11, 2012, 5:09 PM
VulpesPosted Feb 11, 2012, 2:41 PM
RichPosted Feb 10, 2012, 8:33 PM
public class NBASeason
{
public int Season {get;set;}
public datetime date {get;set;}
public string awayTeam {get;set;}
public int awayScore {get;set;}
public string homeTeam {get;set;}
public int homeScore {get;set;}
}
I basically want to calculate each away team's win/loss record, and place it in another class such as:
class AwayRecord
{
public string AwayTeam {get;set;}
public int Wins {get;set}
public int Losses {get;set}
}
I have already made a list that queried the winning away teams:
List<Season> w = this.NBAGetSeasonScores().Where(atw => atw.awayScore > atw.homeScore) .OrderBy(away => away.away).AsEnumerable().ToList();
From this point, I suspect a lambda GroupBy extension method may be needed, as the awayTeam property in the Season class will contain several copies of the same team, but I have yet to correctly figure this out. Hope this makes since. Thanks in advance.
VulpesPosted Feb 7, 2012, 6:02 AM
RichPosted Feb 6, 2012, 8:05 PM
VulpesPosted Feb 6, 2012, 6:27 PM
List
RichPosted Feb 6, 2012, 6:10 PM
List
{
new OffenseStats {Team= "Bears", FGA = 50, FGM = 25},
new OffenseStats {Team= "Lions", FGA = 70, FGM = 20}
};
How can I then create the equation FGM/FGA for each team, and then put the results in a new List:
List
The GoalPercent class would look something like this:
class GoalPercent()
{
public string Team {get; set;}
decimal GoalPercent {get; set;}
public GoalPercent(string team, decimal gp)
{
Team = team;
GoalPercent = gp;
}
}
Thanks in advance.
RichPosted Feb 5, 2012, 3:41 AM
VulpesPosted Feb 4, 2012, 6:23 PM
So, for the first element, 't' will "team1" and 'i' will be 0.
We can then use 'i' to read off the stats for a particular team from the other 2 lists.
RichPosted Feb 4, 2012, 6:15 PM