X hits on this document

PDF document

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

201 views

0 shares

0 downloads

0 comments

40 / 73

Fields

Let’s look at the Car class we created earlier in this chapter:

C#:

public class Car {

private string _make; private string _model;

get

{

return

set

{

_make =

public string Make {

}

_

make; value;

}

}

public string Drive() { if (_make=="Oldsmobile") { return "Chicago"; } else {

return "Toledo";

}

}

}

First lines of code are fields. Fields are simply variables defined within a class, outside the scope of a method (a variable, but with scope that extends outside of a given method). They can be private like we have in the Car example, or they can be public.

Ideally, you should never use Public Fields, but rather use Public Properties instead. We'll talk about that more in a moment, but let’s add three more BEST PRACTICEs to our ongoing list:

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



Document info
Document views201
Page views201
Page last viewedFri Dec 09 22:30:47 UTC 2016
Pages73
Paragraphs821
Words15988

Comments