Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPaul Frivold
1,073 PointsThe type 'GameResult' already contains a definition for 'HomeOrAway'
Working my way through C# streams and data processing, but I've gotten a bit confused. I'll post my code here and explain the problem below.
namespace SoccerStats {
public class GameResult {
public DateTime GameDate { get; set; }
public string TeamName { get; set; }
public HomeOrAway HomeOrAway { get; set; }
public enum HomeOrAway {
Home,
Away
}
}
}
As far as I can tell, I did exactly what the instructor did when creating an enum called HomeOrAway, but I'm getting this error message: The type 'GameResult' already contains a definition for 'HomeOrAway'
The error message disappears if I change the
public HomeOrAway HomeOrAway {get; set; }
toC#
public HomeOrAway AnythingElse { get; set; }
But it seems to work perfectly in the instructors video.... I'm confused.
1 Answer
Roman Fincher
18,267 PointsYou are trying to define HomeOrAway as both an enum and a property in the GameResult class. The enum should not be a part of GameResult, but rather just a member of the SoccerStats namespace (even though you're storing it in the GameResult file, it will be outside of the GameResult class's curly braces).
Paul Frivold
1,073 PointsPaul Frivold
1,073 PointsThank you so much! That makes sense.