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.

VulpesRank #55 · 29.2K reputationPosted Feb 4, 2012, 10:41 AM EST
Rich83 reputationPosted Feb 4, 2012, 1:15 PM EST
VulpesRank #55 · 29.2K reputationPosted Feb 4, 2012, 1:23 PM EST
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.
Rich83 reputationPosted Feb 4, 2012, 10:41 PM EST
Rich83 reputationPosted Feb 6, 2012, 1:10 PM EST
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.
VulpesRank #55 · 29.2K reputationPosted Feb 6, 2012, 1:27 PM EST
List
Rich83 reputationPosted Feb 6, 2012, 3:05 PM EST
VulpesRank #55 · 29.2K reputationPosted Feb 7, 2012, 1:02 AM EST
Rich83 reputationPosted Feb 10, 2012, 3:33 PM EST
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.
VulpesRank #55 · 29.2K reputationPosted Feb 11, 2012, 9:41 AM EST
Rich83 reputationPosted Feb 11, 2012, 12:09 PM EST
Rich83 reputationPosted Feb 13, 2012, 12:33 PM EST
VulpesRank #55 · 29.2K reputationPosted Feb 13, 2012, 1:40 PM EST
Rich83 reputationPosted Feb 13, 2012, 1:57 PM EST
Spread = g.Average(at => Math.Abs((decimal)at.awayScore - (decimal)at.homeScore))
VulpesRank #55 · 29.2K reputationPosted Feb 14, 2012, 5:27 AM EST
Rich83 reputationPosted Feb 14, 2012, 2:27 PM EST
VulpesRank #55 · 29.2K reputationPosted Feb 15, 2012, 12:05 AM EST
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 :)
Rich83 reputationPosted Feb 17, 2012, 4:10 PM EST
VulpesRank #55 · 29.2K reputationPosted Feb 18, 2012, 1:48 AM EST