X hits on this document

PDF document

“Beginning Visual C# 2005 Express Edition Video Series” - page 50 / 73

245 views

0 shares

0 downloads

0 comments

50 / 73

see in the Form1_Load method, or some method that would need to create an instance of the Car class:

C#:

myCar = new Car();

Also, the constructor is ALWAYS the first code to execute within your class, however having a Constructor in your class is optional. While Constructors are not required, it is a good idea to use constructors to initialize the private property (private member) values of your new object.

I’ve used the term “initialize” several times; let me explain what I mean. Initialization is the process of taking steps to ensure that your object will function properly by the time the object is used in an application. That means different things based on how you design your object. For example, you may choose to create a connection to a database, or create instances of child objects, or set variables (like private fields) to default values, etc. The constructor is the perfect place to execute code that MUST RUN in order for your object to perform correctly.

BEST PRACTICE: Use Constructors to initialize values for a newly created object.

Supplemental Readings for the Express Edition Videos Copyright © 2005 LearnVisualStudio.NET



Document info
Document views245
Page views245
Page last viewedFri Jan 20 23:00:46 UTC 2017
Pages73
Paragraphs821
Words15988

Comments