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 trialMitchell Lerdahl
2,471 PointsWhy can I not call my method?
Ok I'm pretty confused on why I can not use my CreateContact method in program.cs
1 Answer
Allan Clark
10,810 PointsThis is an issue with the type of your variable. The 'addressBook' variable is explicitly typed as an 'Information' object instead of a 'Book' object. Since a Book is-a 'Information' in this class set up, the compiler won't complain about putting a Book into an Information typed variable. So essentially that variable does not have access to the method. The easiest fix for this would be to change it to an implicitly typed variable, meaning change line 13 in the Program.cs to this:
var addressBook = new Book();
As a side note, in C# the standard is generally to use implicitly typed variables when the type is easily determined. For example when 'new'-ing up an object, or storing a simple string.
Mitchell Lerdahl
2,471 PointsMitchell Lerdahl
2,471 Pointsah ok that makes a lot of sense, thank you!