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 trial

C# Adding Class Constructors

Stuck - Not sure how to update the Main method so the code compiles successfully: Error CS1729

On the Practice Workshop for C# Classes, Challenge 3, I'm not sure how to "update the Main method" so that I can resolve error CS1729. I reviewed the MSDN for this error and from what I understand the number of parameters in lines 9, 13, and 17 in the Main method should be identical to the number of parameters used to initialize the fields in each class. However, when I did that, I had different errors. Not sure what to do now.

Here's my workspace: (link)[ https://w.trhou.se/xbjxgjsso5]

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Ra Bha! You created constructors that take arguments. You'll see this again in the next video. So you can't just do var albums = new Albums();. That constructor is requiring two arguments. One for the artist and one for the title. So you need to pass in something at the time you do new Albums(); This is true for the rest of your instances of other classes.

So where you have:

var albums = new Albums(); 
albums.Artist = "Pink Floyd";
albums.Title = "Dark Side of the Moon"; 

You will need:

var albums = new Albums("Pink Floyd", "Dark Side of the Moon"); 

After you fix those so that you're passing in the strings to the constructors, you'll get three new errors saying that the protection level is incorrect. This is because none of your constructors are marked as public. You forgot the keyword public in front of the constructor.

For example, in Albums.cs you have:

Albums(string artist, string title)
    {
      Artist = artist;
      Title = title; 
    }

But because you haven't said that it's public, it's assuming it's private or protected.

I'm expecting to see this:

public Albums(string artist, string title)
    {
      Artist = artist;
      Title = title; 
    }

Once I fix the new calls and send in the strings directly as shown above and add the word public before the constructors, your code compiles and runs just fine :tada:

Hope this helps! :sparkles: