O'Reilly logo

Microsoft®C# Programming for the absolute beginner by Andy Harris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Overloading Constructors

Constructors enable you to send parameters when you build an object, but sometimes you don’t want to send any parameters. You can create an object in one of several ways. Classes can have more than one constructor, which makes them even more flexible. If you have more than one constructor, it is known as overloading your constructors.

Viewing the Improved Critter Class

You can make another version of the Critter class that has several constructors with different sets of parameters. Take a look at this version of the critter to see how it works. I’m showing only the constructors in this code listing because nothing else changes.

 using System; namespace CritOver { /// <summary> /// Critter class showing overloaded constructors ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required