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!
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 trial
Mitchell Lerdahl2,471 Points
Why can I not call my method?
Ok I'm pretty confused on why I can not use my CreateContact method in program.cs
Allan Clark10,810 Points
This 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.