To the author of Beginning Visual C# 2010
Please change the example of Ch10Ex01.
...How It Works
The code in Main() creates and uses an instance of the MyClass class defined in MyClass.cs. Instantiating this class must be performed using a nondefault constructor because the default constructor of MyClass is private:
private MyClass() : this("Default Name")
{
}
Using this("Default Name") ensures that Name gets a value if this constructor is ever called, which is possible if this class is used to derive a new class. This is necessary because not assigning a value to the Name field could be a source of errors later. ....
As a beginner, the red-color-marked sentences confused me a long time, it is impossible to call a base-private-constructor from its derived-class. So please change the description in next edition. Or if I am wrong, can you explain this to me and give me an example?
|