X hits on this document

PDF document

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

211 views

0 shares

0 downloads

0 comments

20 / 73

Fields

Let’s look at the Car class we created:

Visual Basic:

Public Class Car Private m_make as string Private m_model as string

Public Property Make() as string Get() return m_make End Get Set(ByVal Value as string) m_make = Value End Set End Property

Public Function Drive() as string if m_make = "Oldsmobile" then return "Chicago" else return "Toledo" end if End Function End Class

First lines of code are fields. Fields are simply variables defined within a class. 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:

BEST PRACTICE: Instead of Public Fields, use Public Properties. As a general rule, keep as many fields and methods private, and make them public only if there is a reason to do so.

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



Document info
Document views211
Page views211
Page last viewedSat Dec 10 16:54:21 UTC 2016
Pages73
Paragraphs821
Words15988

Comments