Data Types and Expressions
Chapter 2 introduced you to the basic elements of a C# program. You discovered the
requirements for developing, compiling, and executing console applications.The applications
you created were restricted to displaying text output, and although these are interesting
applications, they are quite limited.This chapter focuses on data.
is the raw facts—the
basic numbers and characters that are manipulated to produce useful information. In this
chapter, you begin to see the power of programming when you write applications to per-
form calculations.You learn how to declare variables that hold different types of data in
memory and see how arithmetic operators react given different kinds of data.
Programs manipulate data, and data can take the form of a number, single character, or com-
bination of characters.The following are all examples of data:
18,“Brenda”,‘A’, 3.25, –7, 36724, and 47.23
By themselves, these data items have no value.The number 18 could be an age, temperature,
number of students in a class, number of hours you are enrolled in this term, or could represent
something totally different.Without identifying and labeling 18, it is a meaningless number.
When working with data, the Frst task is to use an identiFer to name the data item.
are names of elements that appear in a program, such as data items. Some identi-
Fers are predeFned; others are user deFned.You have already seen some .NET identiFers
when you wrote your Frst program in Chapter 2.These were not reserved keywords, but
simply names selected and used by the developers of the .NET platform and the C# lan-
guage.The program in Example 2-1 contained the following predeFned identiFers:
are user-deFned identiFers selected by the author of the textbook during the creation of the
Here are the rules for creating an identiFer in C#:
1. A combination of alphabetic characters (a–z and A–Z), numeric digits (0–9), and
the underscores (_) can be used. IdentiFers can be long; however, many systems
consider the Frst 31 characters unique.