Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page 376 second paragraph #47

Open
niusz opened this issue Oct 28, 2022 · 1 comment
Open

Page 376 second paragraph #47

niusz opened this issue Oct 28, 2022 · 1 comment

Comments

@niusz
Copy link

niusz commented Oct 28, 2022

 abstract class Canine : Animal
    {
        public bool BelongsToPack { get; protected set; } = false;

    }
}

say it has its own abstract property, BelongsToPack, but why abstract modifier didn't appear before BelongsToPack ,Thanks

@andrewstellman
Copy link
Collaborator

Hi! Thanks for posting this. You're right, BelongsToPack is a concrete method, because abstract classes can contain concrete methods. (Here's the reference for that – 14.2.2.2 Abstract Classes – "An abstract class is permitted (but not required) to contain abstract members.")

We could mark BelongsToPack abstract:

public abstract bool BelongsToPack { get; protected set; } = false;

But then the code wouldn't compile, because the = false; makes it an auto-implemented property, which must be concrete.

So while the book is technically correct, we definitely could do a better job teaching this part! I'm going to have to think about how to handle this—teaching about abstract classes well is challenging, so it's going to take some work to improve this, but I'm definitely going to try! We're working on the 5th edition now (targeting the next version of C#, which will probably be released in November 2023). I'll leave this issue open to track that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants