Skip to Content
Beginning C# 3.0
book

Beginning C# 3.0

by Jack Purdum
May 2008
Beginner
550 pages
13h 22m
English
Wrox
Content preview from Beginning C# 3.0

4.3. Using a Variable in a Program

Now that you understand what a symbol table is and the information it contains, let's examine how Visual Studio processes something as simple as an assignment. Assuming that you have defined an integer variable named i, suppose you write the following statement:

i = 10;

The program statement seems simple enough, but let's examine the steps Visual Studio has to perform to process the statement.

  1. Syntax checking: As before, Visual Studio must first make sure that the program statement obeys the syntax rules of the C# language. Because Intellisense doesn't find anything wrong with the statement's syntax, Visual Studio progresses to the next step.

  2. Symbol table checking: Because the statement wants to assign the value 10 into a variable named i, Visual Studio needs to verify that variable i has been previously defined. Two things could go wrong in this step. First, the programmer may have forgotten to define a variable named i. If you forgot to define variable i, Visual Studio issues the following error message:

    The name 'i' does not exist in the current context

    The second possible problem is that a variable named i was defined, but at a scope level that the current context cannot reach. Without going into details at this moment, the scope of a variable refers to its visibility at each point in a program. As I mentioned in Chapter 3, hiding data is a basic principle of encapsulation and a cornerstone of object-oriented programming. The fact that a variable ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Navigating the Metaverse

Navigating the Metaverse

Cathy Hackl, Dirk Lueth, Tommaso Di Bartolo, John Arkontaky, Yat Siu
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
Capitalism at Risk

Capitalism at Risk

Joseph L. Bower, Herman B. Leonard, Lynn S. Paine

Publisher Resources

ISBN: 9780470261293Purchase book