X hits on this document

PDF document

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

168 views

0 shares

0 downloads

0 comments

38 / 73

C#:

public class Car {

private string make; private string model;

public string Make {

get { return make; set { make = value;

}

}

}

public string Drive() { if (make == “Oldsmobile”) { return “Chicago”; } else {

return “Toledo”;

}

}

Admittedly, this particular class still doesn’t do much but will allow us to see what a real class looks like. First, it has two private fields and a public function. We talked very briefly about scope in video lesson 4 and 5, and the words private and public have special meaning in terms of scope (visibility). I'll have more to say about it later in this chapter as we look at Properties, Fields and Methods.

Before we can interact with the Make property or the Drive function, we must create an instance of the Car class; or rather, we must instantiate the Car object.

C#:

Car myCar; myCar = new Car(); string location; myCar.Make = "Oldsmobile"; myLocation = myCar.Drive();

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



Document info
Document views168
Page views168
Page last viewedMon Dec 05 10:07:52 UTC 2016
Pages73
Paragraphs821
Words15988

Comments