Starting Out With Visual C 2010 2nd Edition Tony Gaddis
Starting Out With Visual C 2010 2nd Edition Tony Gaddis
Starting Out With Visual C 2010 2nd Edition Tony Gaddis
Starting Out With Visual C 2010 2nd Edition Tony Gaddis
1. Starting Out With Visual C 2010 2nd Edition Tony
Gaddis download
https://ebookbell.com/product/starting-out-with-
visual-c-2010-2nd-edition-tony-gaddis-4762738
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Starting Out With Visual C 2010 2nd Ed New International Ed Gaddis
https://ebookbell.com/product/starting-out-with-visual-c-2010-2nd-ed-
new-international-ed-gaddis-6664666
Starting Out With Visual C 5th Edition Tony Gaddis
https://ebookbell.com/product/starting-out-with-visual-c-5th-edition-
tony-gaddis-46257818
Starting Out With Visual C Fourth Edition Gaddis Tony
https://ebookbell.com/product/starting-out-with-visual-c-fourth-
edition-gaddis-tony-21354590
Starting Out With Visual C 3rd Edition Tony Gaddis
https://ebookbell.com/product/starting-out-with-visual-c-3rd-edition-
tony-gaddis-4966972
3. Starting Out With Visual C 2012 3 Global Tony Gaddis
https://ebookbell.com/product/starting-out-with-
visual-c-2012-3-global-tony-gaddis-5716340
Starting Out With Visual C 5e Tony Gaddis
https://ebookbell.com/product/starting-out-with-visual-c-5e-tony-
gaddis-36118552
Starting Out With Visual Basic 2012 6th Ed 6th Ed Gaddis Tonyirvine
https://ebookbell.com/product/starting-out-with-visual-basic-2012-6th-
ed-6th-ed-gaddis-tonyirvine-22125560
Starting Out With Visual Basic 7th Tony Gaddis Kip Irvine
https://ebookbell.com/product/starting-out-with-visual-basic-7th-tony-
gaddis-kip-irvine-10001932
Starting Out With Visual Basic 8th Tony Gaddis Kip Irvine
https://ebookbell.com/product/starting-out-with-visual-basic-8th-tony-
gaddis-kip-irvine-10531320
5. 9 781292 025964
ISBN 978-1-29202-596-4
Starting out with Visual C# 2010
Tony Gaddis
Second Edition
Starting
Out
with
Visual
C#
2010
Gaddis
Second
Edition
8. Table of Contents
P E A R S O N C U S T O M L I B R A R Y
I
1. Introduction to Computers and Programming
1
Tony Gaddis
2. Introduction to Visual C#
55
Tony Gaddis
3. Processing Data
121
Tony Gaddis
4. Making Decisions
201
Tony Gaddis
5. Loops, Files, and Random Numbers
273
Tony Gaddis
6. Modularizing Your Code with Methods
347
Tony Gaddis
7. Arrays and Lists
397
Tony Gaddis
8. More about Processing Data
475
Tony Gaddis
9. Classes and Multiform Projects
547
Tony Gaddis
10. Inheritance and Polymorphism
613
Tony Gaddis
11. Databases
653
Tony Gaddis
Appendix: C# Primitive Data Types
729
Tony Gaddis
Appendix: ASCII/Unicode Characters
731
Tony Gaddis
11. Introduction to Computers and Programming
Figure 1 A word processing program and a presentation program
This text introduces you to the fundamental concepts of computer programming using the
C# programming language. Before we begin exploring those concepts, you need to under-
stand a few basic things about computers and how they work. This chapter provides a
solid foundation of knowledge that you will continually rely on as you study computer sci-
ence. First, we discuss the physical components that computers are commonly made of.
Then, we look at how computers store data and execute programs. Next, we introduce you
to two fundamental elements of modern software design: graphical user interfaces and ob-
jects. Finally, we give a quick introduction to the software used to write C# programs.
Hardware and Software
CONCEPT: The physical devices that a computer is made of are referred to as
the computer’s hardware. The programs that run on a computer are
referred to as software.
Hardware
Hardware refers to all the physical devices, or components, of which a computer is made. A
computer is not one single device but is a system of devices that all work together. Like the
different instruments in a symphony orchestra, each device in a computer plays its own part.
If you have ever shopped for a computer, you have probably seen sales literature listing
components such as microprocessors, memory, disk drives, video displays, graphics cards,
and so on. Unless you already know a lot about computers or at least have a friend who
does, understanding what these different components do can be confusing. As shown in
Figure 2, a typical computer system consists of the following major components:
• The central processing unit (CPU)
• Main memory
• Secondary storage devices
• Input devices
• Output devices
Let’s take a closer look at each of these components.
2
2
12. Introduction to Computers and Programming
Input
Devices
Output
Devices
Secondary
Storage Devices
Central Processing
Unit
Main Memory
(RAM)
Figure 2 Typical components of a computer system
The CPU
When a computer is performing the tasks that a program tells it to do, we say that the com-
puter is running or executing the program. The central processing unit, or CPU, is the part
of a computer that actually runs programs. The CPU is the most important component in a
computer because without it, the computer could not run software.
In the earliest computers, CPUs were huge devices made of electrical and mechanical com-
ponents such as vacuum tubes and switches. Figure 3 shows such a device. The two
Figure 3 The ENIAC computer
U.S. Army Photo
3
13. Introduction to Computers and Programming
women in the photo are working with the historic ENIAC computer. The ENIAC, consid-
ered by many to be the world’s first programmable electronic computer, was built in 1945
to calculate artillery ballistic tables for the U.S. Army. This machine, which was primarily
one big CPU, was 8 feet tall and 100 feet long and weighed 30 tons.
Today, CPUs are small chips known as microprocessors. Figure 4 shows a photo of a lab
technician holding a modern-day microprocessor. In addition to being much smaller than
the old electromechanical CPUs in early computers, microprocessors are also much more
powerful.
Figure 4 A lab technician holds a modern microprocessor
Main Memory
You can think of main memory as the computer’s work area. This is where the computer
stores a program while the program is running, as well as the data that the program is
working with. For example, suppose you are using a word processing program to write an
essay for one of your classes. While you do this, both the word processing program and the
essay are stored in main memory.
Main memory is commonly known as random-access memory, or RAM. It is called
this because the CPU is able to quickly access data stored at any random location in
RAM. RAM is usually a volatile type of memory that is used only for temporary stor-
age while a program is running. When the computer is turned off, the contents of RAM
are erased. Inside your computer, RAM is stored in chips, similar to the ones shown in
Figure 5.
Secondary Storage Devices
Secondary storage is a type of memory that can hold data for long periods of time, even
when there is no power to the computer. Programs are normally stored in secondary
Vadim Kolobanov/Shutterstock
4
14. Introduction to Computers and Programming
Figure 5 Memory chips
memory and loaded into main memory as needed. Important data, such as word pro-
cessing documents, payroll data, and inventory records, is saved to secondary storage as
well.
The most common type of secondary storage device is the disk drive. A disk drive stores
data by magnetically encoding it onto a circular disk. Most computers have a disk drive
mounted inside their case. External disk drives, which connect to one of the computer’s
communication ports, are also available. External disk drives can be used to create
backup copies of important data or to move data to another computer.
In addition to external disk drives, many types of devices have been created for copying
data and for moving it to other computers. For many years floppy disk drives were popu-
lar. A floppy disk drive records data onto a small floppy disk, which can be removed from
the drive. Floppy disks have many disadvantages, however. For example, they have lim-
ited storage capacity, and are slow to access data. The use of floppy disk drives has de-
clined dramatically in recent years in favor of superior devices such as USB drives.
Universal serial bus (USB) drives are small devices that plug into the computer’s USB port
and appear to the system as disk drives. These drives do not actually contain a disk, how-
ever. They store data in a special type of memory known as flash memory. USB drives,
which are also known as memory sticks and flash drives, are inexpensive, reliable, and
small enough to be carried in a pocket.
Optical devices such as the compact disc (CD) and the digital versatile disc (DVD) are also
popular for data storage. Data is not recorded magnetically on an optical disc but is en-
coded as a series of pits on the disc surface. CD and DVD drives use a laser to detect the
pits and thus read the encoded data. Optical discs hold large amounts of data, and be-
cause recordable CD and DVD drives are now commonplace, they are good mediums for
creating backup copies of data.
Input Devices
Input is any data the computer collects from people and from other devices. The compo-
nent that collects the data and sends it to the computer is called an input device. Common
input devices are the keyboard, mouse, scanner, microphone, and digital camera. Disk
drives and optical drives can also be considered input devices because programs and data
are retrieved from them and loaded into the computer’s memory.
Output Devices
Output is any data the computer produces for people or for other devices. It might be a
sales report, a list of names, or a graphic image. The data is sent to an output device, which
formats and presents it. Common output devices are video displays and printers. Disk
drives and CD or DVD recorders can also be considered output devices because the system
sends data to them in order to be saved.
Garsya/Shutterstock
5
15. Introduction to Computers and Programming
Software
If a computer is to function, software is not optional. Everything that a computer does,
from the time you turn the power switch on until you shut the system down, is under the
control of software. There are two general categories of software: system software and ap-
plication software. Most computer programs clearly fit into one of these two categories.
Let’s take a closer look at each.
System Software
The programs that control and manage the basic operations of a computer are generally
referred to as system software. System software typically includes the following types of
programs:
Operating Systems
An operating system is the most fundamental set of programs on a computer. The oper-
ating system controls the internal operations of the computer’s hardware, manages all
the devices connected to the computer, allows data to be saved to and retrieved from
storage devices, and allows other programs to run on the computer.
Utility Programs
A utility program performs a specialized task that enhances the computer’s operation
or safeguards data. Examples of utility programs are virus scanners, file-compression
programs, and data-backup programs.
Software Development Tools
The software tools that programmers use to create, modify, and test software are
referred to as software development tools. Assemblers, compilers, and interpreters, which
are discussed later in this chapter, are examples of programs that fall into this category.
Application Software
Programs that make a computer useful for everyday tasks are known as application soft-
ware. These are the programs that people normally spend most of their time running on
their computers. Figure 1, at the beginning of this chapter, shows screens from two com-
monly used applications—Microsoft Word, a word processing program, and Microsoft
Powerpoint, a presentation program. Some other examples of application software are
spreadsheet programs, e-mail programs, Web browsers, and game programs.
Checkpoint
1 What is a program?
2 What is hardware?
3 List the five major components of a computer system.
4 What part of the computer actually runs programs?
5 What part of the computer serves as a work area to store a program and its data
while the program is running?
6 What part of the computer holds data for long periods of time, even when there is
no power to the computer?
7 What part of the computer collects data from people and from other devices?
8 What part of the computer formats and presents data for people or other devices?
6
16. Introduction to Computers and Programming
9 What fundamental set of programs control the internal operations of the
computer’s hardware?
10 What do you call a program that performs a specialized task, such as a virus
scanner, a file-compression program, or a data-backup program?
11 Word processing programs, spreadsheet programs, e-mail programs, Web
browsers, and game programs belong to what category of software?
How Computers Store Data
CONCEPT: All data stored in a computer is converted to sequences of 0s and 1s.
A computer’s memory is divided into tiny storage locations known as bytes. One byte is
enough memory to store only a letter of the alphabet or a small number. In order to do any-
thing meaningful, a computer has to have lots of bytes. Most computers today have mil-
lions, or even billions, of bytes of memory.
Each byte is divided into eight smaller storage locations known as bits. The term bit
stands for binary digit. Computer scientists usually think of bits as tiny switches that can
be either on or off. Bits aren’t actual “switches,” however, at least not in the conventional
sense. In most computer systems, bits are tiny electrical components that can hold either a
positive or a negative charge. Computer scientists think of a positive charge as a switch in
the on position and a negative charge as a switch in the off position. Figure 6 shows the
way that a computer scientist might think of a byte of memory: as a collection of switches
that are each flipped to either the on or the off position.
3
OFF
ON
OFF OFF
OFF
ON ON ON
Figure 6 A byte thought of as eight switches
The number 77 stored in a byte. The letter A stored in a byte.
OFF
ON
OFF OFF
OFF
ON ON ON
OFF
ON
OFF OFF OFF OFF OFF
ON
Figure 7 Bit patterns for the number 77 and the letter A
When a piece of data is stored in a byte, the computer sets the eight bits to an on/off pattern
that represents the data. For example, the pattern shown on the left in Figure 7 shows how
the number 77 would be stored in a byte, and the pattern on the right shows how the letter
A would be stored in a byte. In a moment you will see how these patterns are determined.
7
17. Introduction to Computers and Programming
Storing Numbers
A bit can be used in a very limited way to represent numbers. Depending on whether the bit
is turned on or off, it can represent one of two different values. In computer systems, a bit
that is turned off represents the number 0 and a bit that is turned on represents the number
1. This corresponds perfectly to the binary numbering system. In the binary numbering sys-
tem (or binary, as it is usually called), all numeric values are written as sequences of 0s and
1s. Here is an example of a number that is written in binary:
10011101
The position of each digit in a binary number has a value assigned to it. Starting with the
rightmost digit and moving left, the position values are 20
, 21
, 22
, 23
, and so forth, as shown
in Figure 8. Figure 9 shows the same diagram with the position values calculated. Starting
with the rightmost digit and moving left, the position values are 1, 2, 4, 8, and so forth.
1 0 0 1 1 1 0 1
20
21
22
23
24
25
26
27
Figure 8 The values of binary digits as powers of 2
1
2
4
8
16
32
64
128
1 0 0 1 1 1 0 1
Figure 9 The values of binary digits
1 0 0 1 1 1 0 1
1
4
8
16
128
1 + 4 + 8 + 16 + 128 = 157
Figure 10 Determining the value of 10011101
To determine the value of a binary number, you simply add up the position values of all
the 1s. For example, in the binary number 10011101, the position values of the 1s are
1, 4, 8, 16, and 128. This is shown in Figure 10. The sum of all these position values is
157. So, the value of the binary number 10011101 is 157.
8
18. Introduction to Computers and Programming
128 + 16 + 8 + 4 + 1 = 157
1
128 64 32 16 8 4 2 1
Position
values
1
0
1
1 1 1
0 0
Figure 11 The bit pattern for 157
Figure 11 shows how you can picture the number 157 stored in a byte of memory. Each 1 is
represented by a bit in the on position, and each 0 is represented by a bit in the off position.
When all the bits in a byte are set to 0 (turned off), then the value of the byte is 0. When
all the bits in a byte are set to 1 (turned on), then the byte holds the largest value that can
be stored in it. The largest value that can be stored in a byte is 1 ⫹ 2 ⫹ 4 ⫹ 8 ⫹ 16 ⫹ 32 ⫹
64 ⫹ 128 ⫽ 255. This limit exists because there are only eight bits in a byte.
What if you need to store a number larger than 255? The answer is simple: use more than
1 byte. For example, suppose we put 2 bytes together. That gives us 16 bits. The position
values of those 16 bits would be 20
, 21
, 22
, 23
, and so forth, up through 215
. As shown in
Figure 12, the maximum value that can be stored in 2 bytes is 65,535. If you need to store
a number larger than this, then more bytes are necessary.
32768 + 16384 + 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 65535
128 64 32 16 8 4 2 1
16384 8192 4096 2048 512 256
1024
32768
Position
values
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Figure 12 Two bytes used for a large number
Storing Characters
Any piece of data that is stored in a computer’s memory must be stored as a binary number.
That includes characters such as letters and punctuation marks. When a character is stored
in memory, it is first converted to a numeric code. The numeric code is then stored in mem-
ory as a binary number.
TIP: In case you’re feeling overwhelmed by all this, relax! You will not have to ac-
tually convert numbers to binary while programming. Knowing that this process is
taking place inside the computer will help you as you learn, and in the long term this
knowledge will make you a better programmer.
9
19. Introduction to Computers and Programming
Over the years, different coding schemes have been developed to represent characters in
computer memory. Historically, the most important of these coding schemes is ASCII,
which stands for the American Standard Code for Information Interchange. ASCII is a set
of 128 numeric codes that represent the English letters, various punctuation marks, and
other characters. For example, the ASCII code for the uppercase letter A is 65. When you
type an uppercase A on your computer keyboard, the number 65 is stored in memory (as
a binary number, of course). This is shown in Figure 13.
65
A 0
0
1
0
1
0 0 0
Figure 13 The letter A stored in memory as the number 65
In case you are curious, the ASCII code for uppercase B is 66, for uppercase C is 67, and
so forth.
The ASCII character set was developed in the early 1960s and was eventually adopted by
almost all computer manufacturers. ASCII is limited, however, because it defines codes for
only 128 characters. To remedy this, the Unicode character set was developed in the early
1990s. Unicode is an extensive encoding scheme that is compatible with ASCII and can
also represent the characters of many of the world’s languages. Today, Unicode is quickly
becoming the standard character set used in the computer industry.
Advanced Number Storage
Earlier you saw how numbers are stored in memory. Perhaps it occurred to you then that
the binary numbering system can be used to represent only integer numbers, beginning with
0. Negative numbers and real numbers (such as 3.14159) cannot be represented using the
simple binary numbering technique we discussed.
Computers are able to store negative numbers and real numbers in memory, but to do so
they use encoding schemes along with the binary numbering system. Negative numbers
are encoded using a technique known as two’s complement, and real numbers are en-
coded in floating-point notation. You don’t need to know how these encoding schemes
work, only that they are used to convert negative numbers and real numbers to binary
format.
Other Types of Data
Computers are often referred to as digital devices. The term digital can be used to describe
anything that uses binary numbers. Digital data is data that is stored in binary, and a digital
device is any device that works with binary data. In this section we have discussed how
numbers and characters are stored in binary, but computers also work with many other
types of digital data.
For example, consider the pictures that you take with your digital camera. These images are
composed of tiny dots of color known as pixels. (The term pixel stands for picture element.)
TIP: The acronym ASCII is pronounced “askee.”
10
20. Introduction to Computers and Programming
As shown in Figure 14, each pixel in an image is converted to a numeric code that represents
the pixel’s color. The numeric code is stored in memory as a binary number.
1001010111
0
1
0
0
0
10101101
Figure 14 A digital image stored in binary format
The music that you play on your CD player, iPod, or MP3 player is also digital. A digital
song is broken into small pieces known as samples. Each sample is converted to a binary
number, which can be stored in memory. The more samples that a song is divided into, the
more it sounds like the original music when it is played back. A CD-quality song is di-
vided into more than 44,000 samples per second!
Checkpoint
12 What amount of memory is enough to store a letter of the alphabet or a small
number?
13 What do you call a tiny “switch” that can be set to either on or off?
14 In what numbering system are all numeric values written as sequences of 0s and 1s?
15 What is the purpose of ASCII?
16 What encoding scheme is extensive enough to represent all the characters of many
of the languages in the world?
17 What do the terms digital data and digital device mean?
How a Program Works
CONCEPT: A computer’s CPU can understand only instructions written in ma-
chine language. Because people find it very difficult to write entire
programs in machine language, other programming languages have
been invented.
Earlier, we stated that the CPU is the most important component in a computer because it
is the part of the computer that runs programs. Sometimes the CPU is called the “com-
puter’s brain,” and is described as being “smart.” Although these are common metaphors,
you should understand that the CPU is not a brain, and it is not smart. The CPU is an elec-
tronic device that is designed to do specific things. In particular, the CPU is designed to per-
form operations such as the following:
• Reading a piece of data from main memory
• Adding two numbers
• Subtracting one number from another number
• Multiplying two numbers
• Dividing one number by another number
• Moving a piece of data from one memory location to another
• Determining whether one value is equal to another value.
4
11
21. Introduction to Computers and Programming
As you can see from this list, the CPU performs simple operations on pieces of data. The
CPU does nothing on its own, however. It has to be told what to do, which is the purpose
of a program. A program is nothing more than a list of instructions that cause the CPU to
perform operations.
Each instruction in a program is a command that tells the CPU to perform a specific op-
eration. Here’s an example of an instruction that might appear in a program:
10110000
To you and me, this is only a series of 0s and 1s. To a CPU, however, this is an instruction
to perform an operation.1
It is written in 0s and 1s because CPUs understand only
instructions that are written in machine language, and machine language instructions are
always written in binary.
A machine language instruction exists for each operation that a CPU is capable of per-
forming. For example, there is an instruction for adding numbers; there is an instruction
for subtracting one number from another; and so forth. The entire set of instructions that
a CPU can execute is known as the CPU’s instruction set.
NOTE: There are several microprocessor companies today that manufacture CPUs.
Some of the more well-known microprocessor companies are Intel, AMD, and
Motorola. If you look carefully at your computer, you might find a tag showing a logo
for its microprocessor.
Each brand of microprocessor has its own unique instruction set, which is typically
understood only by microprocessors of the same brand. For example, Intel micro-
processors understand the same instructions, but they do not understand instructions
for Motorola microprocessors.
The machine language instruction that was previously shown is an example of only
one instruction. It takes a lot more than one instruction, however, for the computer to
do anything meaningful. Because the operations that a CPU knows how to perform are
so basic in nature, a meaningful task can be accomplished only if the CPU performs
many operations. For example, if you want your computer to calculate the amount of
interest that you will earn from your savings account this year, the CPU will have to
perform a large number of instructions, carried out in the proper sequence. It is not un-
usual for a program to contain thousands or even a million or more machine language
instructions.
Programs are usually stored on a secondary storage device such as a disk drive. When you
install a program on your computer, the program is typically copied to your computer’s
disk drive from a CD-ROM or perhaps downloaded from a Web site.
Although a program can be stored on a secondary storage device such as a disk drive,
it has to be copied into main memory, or RAM, each time the CPU executes it. For ex-
ample, suppose you have a word processing program on your computer’s disk. To exe-
cute the program, you use the mouse to double-click the program’s icon. This causes
the program to be copied from the disk into main memory. Then, the computer’s CPU
executes the copy of the program that is in main memory. This process is illustrated in
Figure 15.
1
The example shown is an actual instruction for an Intel microprocessor. It tells the microprocessor to move a
value into the CPU.
12
22. Introduction to Computers and Programming
When a CPU executes the instructions in a program, it is engaged in a process that is
known as the fetch-decode-execute cycle. This cycle, which consists of three steps, is re-
peated for each instruction in the program. The steps are as follows:
1. Fetch A program is a long sequence of machine language instructions. The first step
of the cycle is to fetch, or read, the next instruction from memory into the CPU.
2. Decode A machine language instruction is a binary number that represents a com-
mand that tells the CPU to perform an operation. In this step the CPU decodes the
instruction that was just fetched from memory, to determine which operation it
should perform.
3. Execute The last step in the cycle is to execute, or perform, the operation.
Figure 16 illustrates these steps.
Main memory
(RAM)
Disk drive
CPU
The program is copied
from secondary storage
to main memory.
The CPU executes
the program in
main memory.
Figure 15 A program being copied into main memory and then executed
CPU
Main memory
(RAM)
10111000
10100001
10011110
00011010
11011100
and so forth...
10100001
1
Fetch the next instruction
in the program.
Decode the instruction
to determine which
operation to perform.
3
Execute the instruction
(perform the operation).
2
Figure 16 The fetch-decode-execute cycle
From Machine Language to Assembly Language
Computers can execute only programs that are written in machine language. As previously
mentioned, a program can have thousands or even a million or more binary instructions,
and writing such a program would be very tedious and time consuming. Programming in
machine language would also be very difficult because putting a 0 or a 1 in the wrong place
would cause an error.
Although a computer’s CPU understands only machine language, it is impractical for people
to write programs in machine language. For this reason, assembly language was created in
13
23. Introduction to Computers and Programming
the early days of computing2
as an alternative to machine language. Instead of using binary
numbers for instructions, assembly language uses short words that are known as
mnemonics. For example, in assembly language, the mnemonic add typically means to add
numbers, mul typically means to multiply numbers, and mov typically means to move a
value to a location in memory. When a programmer uses assembly language to write a pro-
gram, he or she can write short mnemonics instead of binary numbers.
NOTE: There are many different versions of assembly language. It was mentioned
earlier that each brand of CPU has its own machine language instruction set. Each
brand of CPU typically has its own assembly language as well.
Assembly language programs cannot be executed by the CPU, however. The CPU under-
stands only machine language, so a special program known as an assembler is used to
translate an assembly language program to a machine language program. This process is
shown in Figure 17. The CPU can then execute the machine language program that the as-
sembler creates.
mov eax, Z
add eax, 2
mov Y, eax
and so forth...
Assembler
10111000
10100001
10011110
and so forth...
Assembly Language
Program
Machine Language
Program
Figure 17 An assembler translating an assembly language program to a machine
language program
High-Level Languages
Although assembly language makes it unnecessary to write binary machine language in-
structions, it is not without difficulties. Assembly language is primarily a direct substitute
for machine language, and like machine language, it requires that you know a lot about the
CPU. Assembly language also requires that you write a large number of instructions for
even the simplest program. Because assembly language is so close in nature to machine lan-
guage, it is referred to as a low-level language.
In the 1950s, a new generation of programming languages known as high-level languages
began to appear. A high-level language allows you to create powerful and complex pro-
grams without knowing how the CPU works and without writing large numbers of low-
level instructions. In addition, most high-level languages use words that are easy to
understand. For example, if a programmer were using COBOL (which was one of the
early high-level languages created in the 1950s), he or she would write the following in-
struction to display the message Hello world on the computer screen:
DISPLAY "Hello world"
2
The first assembly language was most likely developed in the 1940s at Cambridge University for use with a
historical computer known as the EDSAC.
14
24. Introduction to Computers and Programming
Doing the same thing in assembly language would require several instructions and an in-
timate knowledge of how the CPU interacts with the computer’s video circuitry. As you
can see from this example, high-level languages allow programmers to concentrate on the
tasks they want to perform with their programs rather than the details of how the CPU
will execute those programs.
Since the 1950s, thousands of high-level languages have been created. Table 1 lists several
of the more well-known languages.
Table 1 Programming languages
Language Description
Ada Ada was created in the 1970s, primarily for applications used by the U.S.
Department of Defense. The language is named in honor of Countess Ada
Lovelace, an influential and historical figure in the field of computing.
BASIC Beginners All-purpose Symbolic Instruction Code is a general-purpose language
that was originally designed in the early 1960s to be simple enough for beginners
to learn. Today, there are many different versions of BASIC.
FORTRAN FORmula TRANslator was the first high-level programming language. It was
designed in the 1950s for performing complex mathematical calculations.
COBOL Common Business-Oriented Language was created in the 1950s and was designed
for business applications.
Pascal Pascal was created in 1970 and was originally designed for teaching programming.
The language was named in honor of the mathematician, physicist, and
philosopher Blaise Pascal.
C and C++ C and C++ (pronounced “c plus plus”) are powerful, general-purpose languages
developed at Bell Laboratories. The C language was created in 1972, and the
C++ language was created in 1983.
C# Pronounced “c sharp,” this language was created by Microsoft around the year
2000 for developing applications based on the Microsoft .NET platform.
Java Java was created by Sun Microsystems in the early 1990s. It can be used to develop
programs that run on a single computer or over the Internet from a Web server.
JavaScript JavaScript, created in the 1990s, can be used in Web pages. Despite its name,
JavaScript is not related to Java.
Python Python is a general-purpose language created in the early 1990s. It has become
popular in business and academic applications.
Ruby Ruby is a general-purpose language that was created in the 1990s. It is increasingly
becoming a popular language for programs that run on Web servers.
Visual Basic Visual Basic (commonly known as VB) is a Microsoft programming language
and software development environment that allows programmers to create
Windows-based applications quickly. VB was originally created in the early 1990s.
Keywords, Operators, and Syntax: An Overview
Each high-level language has its own set of predefined words that the programmer must use
to write a program. The words that make up a high-level programming language are known
as keywords or reserved words. Each keyword has a specific meaning and cannot be used
for any other purpose. Table 2 shows the keywords in the C# programming language.
15
25. Introduction to Computers and Programming
In addition to keywords, programming languages have operators that perform various
operations on data. For example, all programming languages have math operators that
perform arithmetic. In C#, as well as most other languages, the + sign is an operator that
adds two numbers. The following adds 12 and 75:
12 + 75
There are numerous other operators in the C# language, many of which you will learn
about as you progress through this text.
In addition to keywords and operators, each language also has its own syntax, which is a
set of rules that must be strictly followed when writing a program. The syntax rules dic-
tate how keywords, operators, and various punctuation characters must be used in a pro-
gram. When you are learning a programming language, you must learn the syntax rules
for that particular language.
The individual instructions that you use to write a program in a high-level programming
language are called statements. A programming statement can consist of keywords, oper-
ators, punctuation, and other allowable programming elements, arranged in the proper
sequence to perform an operation.
Compilers and Interpreters
Because the CPU understands only machine language instructions, programs that are writ-
ten in a high-level language must be translated into machine language. Depending on the
language in which a program has been written, the programmer will use either a compiler
or an interpreter to make the translation.
A compiler is a program that translates a high-level language program into a separate ma-
chine language program. The machine language program can then be executed any time it
Table 2 The C# keywords
abstract as base bool
break byte case catch
char checked class const
continue decimal default delegate
do double else enum
event explicit extern false
finally fixed float for
foreach goto if implicit
in in int interface
internal is lock long
namespace new null object
operator out out override
params private protected public
readonly ref return sbyte
sealed short sizeof stackalloc
static string struct switch
this throw true try
typeof uint ulong unchecked
unsafe ushort using virtual
void volatile while
16
26. Introduction to Computers and Programming
is needed. This is shown in Figure 18. As shown in the figure, compiling and executing are
two different processes.
Some programming languages use an interpreter, which is a program that both translates
and executes the instructions in a high-level language program. As the interpreter reads
each individual instruction in the program, it converts it to a machine language instruc-
tion and then immediately executes it. This process repeats for every instruction in the
program. This process is illustrated in Figure 19. Because interpreters combine translation
and execution, they typically do not create separate machine language programs.
Display "Hello
Earthling"
and so forth...
High-level language
program
Compiler
10111000
10100001
10011110
and so forth...
10111000
10100001
10011110
and so forth...
Machine language
program
Machine language
program
CPU
The compiler is used
to translate the high-level
language program to a
machine language program.
The machine language
program can be executed
at any time, without using
the compiler.
1
2
Figure 18 Compiling a high-level program and executing it
The interpreter translates each high-level instruction to
its equivalent machine language instructions and
immediately executes them.
This process is repeated for each high-level instruction.
Display "Hello
Earthling"
and so forth...
program
Interpreter 10100001
Machine language
instruction
CPU
Figure 19 Executing a high-level program with an interpreter
The statements that a programmer writes in a high-level language are called source code,
or simply code. Typically, the programmer types a program’s code into a text editor and
then saves the code in a file on the computer’s disk. Next, the programmer uses a compiler
to translate the code into a machine language program or an interpreter to translate and
execute the code. If the code contains a syntax error, however, it cannot be translated. A
syntax error is a mistake such as a misspelled keyword, a missing punctuation character,
or the incorrect use of an operator. When this happens, the compiler or interpreter dis-
plays an error message, indicating that the program contains a syntax error. The pro-
grammer corrects the error and then attempts once again to translate the program.
17
27. Introduction to Computers and Programming
Checkpoint
18 A CPU understands instructions that are written only in what language?
19 A program has to be copied into what type of memory each time the CPU
executes it?
20 When a CPU executes the instructions in a program, it is engaged in what
process?
21 What is assembly language?
22 What type of programming language allows you to create powerful and complex
programs without knowing how the CPU works?
23 Each language has a set of rules that must be strictly followed when writing a
program. What is this set of rules called?
24 What do you call a program that translates a high-level language program into a
separate machine language program?
25 What do you call a program that both translates and executes the instructions in
a high-level language program?
26 What type of mistake is usually caused by a misspelled keyword, a missing
punctuation character, or the incorrect use of an operator?
Graphical User Interfaces
CONCEPT: A graphical user interface allows the user to interact with a pro-
gram using graphical elements such as icons, buttons, and dialog
boxes.
Programmers commonly use the term user to describe any hypothetical person that might
be using a computer and its programs. A computer’s user interface is the part of the com-
puter with which the user interacts. One part of the user interface consists of hardware de-
vices, such as the keyboard and the video display. Another part of the user interface
involves the way that the computer’s operating system and application software accepts
commands from the user. For many years, the only way that the user could interact with a
computer was through a command line interface. A command line interface, which is also
known as a console interface, requires the user to type commands. If a command is typed
correctly, it is executed and the results are displayed. If a command is not typed correctly,
an error message is displayed. Figure 20 shows the Windows command prompt window,
which is an example of a command line interface.
5
NOTE: Human languages also have syntax rules. Do you remember when you took
your first English class and you learned all those rules about commas, apostrophes,
capitalization, and so forth? You were learning the syntax of the English language.
Although people commonly violate the syntax rules of their native language when
speaking and writing, other people usually understand what they mean. Unfortu-
nately, compilers and interpreters do not have this ability. If even a single syntax error
appears in a program, the program cannot be compiled or executed.
18
28. Introduction to Computers and Programming
Many computer users, especially beginners, find command line interfaces difficult to use. This
is because there are many commands to be learned, and each command has its own syntax,
much like a programming statement. If a command isn’t entered correctly, it will not work.
In the 1980s, a new type of interface known as a graphical user interface came into use in
commercial operating systems. A graphical user interface, or GUI (pronounced “gooey”),
allows the user to interact with the operating system and application programs through
graphical elements on the screen. GUIs also popularized the use of the mouse as an input
device. Instead of requiring the user to type commands on the keyboard, GUIs allow the
user to point at graphical elements and click the mouse button to activate them.
Much of the interaction with a GUI is done through windows that display information
and allow the user to perform actions. Figure 21 shows an example of a window that al-
lows the user to change the system’s Internet settings. Instead of typing cryptic commands,
the user interacts with graphical elements such as icons, buttons, and slider bars.
Figure 20 A command line interface
Figure 21 A window in a graphical user interface
19
29. Introduction to Computers and Programming
Figure 23 A GUI program
Figure 22 Interaction with a program in a text environment
Event-Driven GUI Programs
In a text-based environment, such as a command line interface, programs determine the
order in which things happen. For example, Figure 22 shows the interaction that has taken
place in a text environment with a program that calculates an employee’s gross pay. First,
the program told the user to enter the number of hours worked. In the figure, the user en-
tered 40 and pressed the Enter key. Next, the program told the user to enter his or her
hourly pay rate. In the figure, the user entered 50.00, and pressed the Enter key. Then, the
program displayed the user’s gross pay. As the program was running, the user had no choice
but to enter the data in the order requested.
In a GUI environment, however, the user determines the order in which things happen.
For example, Figure 23 shows a GUI program that calculates an employee’s gross pay.
Notice that there are boxes in which the user enters the number of hours worked and the
hourly pay rate. The user can enter the hours and the pay rate in any order he or she
wishes. If the user makes a mistake, the user can erase the data that was entered and re-
type it. When the user is ready to calculate the area, he or she uses the mouse to click the
Calculate Gross Pay button and the program performs the calculation.
Because GUI programs must respond to the actions of the user, they are said to be event
driven. The user causes events, such as the clicking of a button, and the program responds
to those events.
This text focuses exclusively on the development of GUI applications using the C# pro-
gramming language. You will learn to create applications that interact with the user
through windows containing graphical objects. You will also learn how to program your
applications to respond to the events that take place as the user interacts with them.
Checkpoint
27 What is a user interface?
28 How does a command line interface work?
20
30. Introduction to Computers and Programming
29 When the user runs a program in a text-based environment, such as the command
line, what determines the order in which things happen?
30 What is an event-driven program?
Objects
CONCEPT: An object is a program component that contains data and performs
operations. Programs use objects to perform specific tasks.
Have you ever driven a car? If so, you know that a car is made of a lot of components. A
car has a steering wheel, an accelerator pedal, a brake pedal, a gear shifter, a speedometer,
and numerous other devices with which the driver interacts. There are also a lot of compo-
nents under the hood, such as the engine, the battery, the radiator, and so forth. A car is not
just one single object, but rather a collection of objects that work together.
This same notion also applies to computer programming. Most programming languages
that are used today are object oriented. When you use an object-oriented language, you
create programs by putting together a collection of objects. In programming, an object is
not a physical device, however, like a steering wheel or a brake pedal. Instead, it is a soft-
ware component that exists in the computer’s memory. In software, an object has two
general capabilities:
• An object can store data. The data stored in an object are commonly called fields, or
properties.
• An object can perform operations. The operations that an object can perform are
called methods.
When you write a program using an object-oriented language, you use objects to accom-
plish specific tasks. Some objects have a visual part that can be seen on the screen. For ex-
ample, Figure 24 shows the wage-calculator program that we discussed in the previous
section. The graphical user interface is made of the following objects:
Form object A window that is displayed on the screen is called a Form object.
Figure 24 shows a Form object that contains several other graphi-
cal objects.
Label objects A Label object displays text on a form. The form shown in Figure
24 contains two Label objects. One of the Label objects displays
the text Number of Hours Worked and the other Label object dis-
plays the text Hourly Pay Rate.
6
TextBox objects
Label objects
Button objects
Form object
Figure 24 Objects used in a GUI
21
31. Introduction to Computers and Programming
TextBox objects A TextBox object appears as a rectangular region that can accept
keyboard input from the user. The form shown in Figure 24 has
two TextBox objects: one in which the user enters the number
of hours worked and another in which the user enters the hourly
pay rate.
Button objects A Button object appears on a form as a button with a caption writ-
ten across its face. When the user clicks a Button object with the
mouse, an action takes place. The form in Figure 24 has two But-
ton objects. One shows the caption Calculate Gross Pay. When the
user clicks this button, the program calculates and displays the
gross pay. The other button shows the caption Exit. When the user
clicks this button, the program ends.
Forms, Labels, TextBoxes, and Buttons are just a few of the objects that you will learn to
use in C#.
Visible versus Invisible Objects
Objects that are visible in a program’s graphical user interface are commonly referred
to as controls. We could say that the form shown in Figure 24 contains two Label con-
trols, two TextBox controls, and two Button controls. When an object is referred to as
a control, it simply means that the object plays a role in a program’s graphical user in-
terface.
Not all objects can be seen on the screen, however. Some objects exist only in memory for
the purpose of helping your program perform some task. For example, there are objects
that read data from files, objects that generate random numbers, objects that store and
sort large collections of data, and so forth. These types of objects help your program per-
form tasks, but they do not directly display anything on the screen. When you are writing
a program, you will use objects that can help your program perform its tasks. Some of the
objects that you use will be controls (visible in the program’s GUI), and other objects will
be invisible.
Classes: Where Objects Come From
Objects are very useful, but they don’t just magically appear in your program. Before a
specific type of object can be used, that object has to be created in memory. And, before an
object can be created in memory, you must have a class for the object.
A class is code that describes a particular type of object. It specifies the data that an object
can hold (the object’s fields and properties), and the actions that an object can perform
(the object’s methods). You will learn much more about classes as you progress through
this text, but for now, just think of a class as a code “blueprint” that can be used to create
a particular type of object.
The .NET Framework
C# is a very popular programming language, but there are a lot of things it cannot do by
itself. For example, you cannot use C# alone to create a graphical user interface, read data
from files, work with databases, or many of the other things that programs commonly
need to do. C# provides only the basic keywords and operators that you need to construct
a program.
So, if the C# language doesn’t provide the classes and other code necessary for creating
GUIs and performing many other advanced operations, where do those classes and code
22
32. Introduction to Computers and Programming
come from? The answer is the .NET Framework. The .NET Framework is a collection of
classes and other code that can be used, along with a programming language such as C#,
to create programs for the Windows operating system. For example, the .NET Frame-
work provides classes to create Forms, TextBoxes, Labels, Buttons, and many other types
of objects.
When you use Visual C# to write programs, you are using a combination of the C#
language and the .NET Framework. As you work through this text you will not only learn
C#, but you will also learn about many of the classes and other features provided by the
.NET Framework.
Writing Your Own Classes
The .NET Framework provides many prewritten classes ready for use in your programs.
There will be times, however, that you will wish you had an object to perform a specific
task, and no such class will exist in the .NET Framework. This is not a problem because in
C# you can write your own classes that have the specific fields, properties, and methods
that you need for any situation.
Checkpoint
31 What is an object?
32 What type of language is used to create programs by putting together a collection
of objects?
33 What two general capabilities does an object have?
34 What term is commonly used to refer to objects such as TextBoxes, Labels, and
Buttons that are visible in a program’s graphical user interface?
35 What is the purpose of an object that cannot be seen on the screen and exists only
in memory?
36 What is a class?
37 What is the .NET Framework?
38 Why might you need to write your own classes?
The Program Development Process
CONCEPT: Creating a program requires several steps, which include designing
the program’s logic, creating the user interface, writing code,
testing, and debugging.
The Program Development Cycle
Previously in this chapter you learned that programmers typically use high-level languages
such as C# to create programs. There is much more to creating a program than writing
code, however. The process of creating a program that works correctly typically requires
the six phases shown in Figure 25. The entire process is known as the program develop-
ment cycle.
7
23
33. Introduction to Computers and Programming
Let’s take a closer look at each stage in the cycle.
1. Understand the Program’s Purpose
When beginning a new programming project, it is essential that you understand what
the program is supposed to do. Most programs perform the following three-step
process:
Step 1. Input is received.
Step 2. Some process is performed on the input.
Step 3. Output is produced.
Input is any data that the program receives while it is running. Once input is received,
some process, such as a mathematical calculation, is usually performed on it. The re-
sults of the process are then sent out of the program as output. If you can identify
these three elements of a program (input, process, and output), then you are on your
way to understanding what the program is supposed to do.
For example, suppose you have been asked to write a program to calculate and dis-
play the gross pay for an hourly paid employee. Here is a summary of the program’s
input, process, and output:
Input:
• Input the number of hours that the employee worked.
• Input the employee’s hourly pay rate.
Process:
• Multiply the number of hours worked by the hourly pay rate. The result is the
employee’s gross pay.
Output:
• Display the employee’s gross pay on the screen.
2. Design the Graphical User Interface (GUI)
Once you clearly understand what the program is supposed to do, you can begin de-
signing its graphical user interface. Often, you will find it helpful to draw a sketch of
each form that the program displays. For example, if you are designing a program that
calculates gross pay, Figure 26 shows how you might sketch the program’s form.
Notice that the sketch identifies each type of control (GUI object) that will appear
on the form. The TextBox controls will allow the user to enter input. The user will
type the number of hours worked into one of the TextBoxes and the employee’s
hourly pay rate into the other TextBox. Notice that Label controls are placed on the
form to tell the user what data to enter. When the user clicks the Button control that
reads Calculate Gross Pay, the program will display the employee’s gross pay on the
screen in a pop-up window. When the user clicks the Button control that reads Exit,
the program will end.
Once you are satisfied with the sketches that you have created for the program’s
forms, you can begin creating the actual forms on the computer. As a Visual C# pro-
grammer, you have a powerful environment known as Visual Studio at your disposal.
Visual Studio gives you a “what you see is what you get” editor that allows you to
visually design a program’s forms. You can use Visual Studio to create the program’s
Understand the
Program's Purpose
Design the
Program's GUI
Design the
Program's Logic
Write the Code
Correct Syntax
Errors
Test the Program &
Correct Logic Errors
Figure 25 The program development cycle
24
34. Introduction to Computers and Programming
forms, place all the necessary controls on the forms, and set each control’s properties
so it has the desired appearance. For example, Figure 27 shows the actual form that
you might create for the wage-calculator program, which calculates gross pay.
Number of Hours Worked
Hourly Pay Rate
Calculate
Gross Pay
Exit
TextBox control
TextBox control
Button control Button control
Label control
Label control
Figure 26 Form sketch
Figure 27 Form for the wage-calculator program
3. Design the Program’s Logic
In this phase you break down each task that the program must perform into a series
of logical steps. For example, if you look back at Figure 27, notice that the pay-
calculating program’s form has a Button control that reads Calculate Gross Pay.
When the user clicks this button, you want the program to display the employee’s
gross pay. Here are the steps that the program should take to perform that task:
Step 1. Get the number of hours worked from the appropriate TextBox.
Step 2. Get the hourly pay rate from the appropriate TextBox.
Step 3. Calculate the gross pay as the number of hours worked times the hourly pay
rate.
Step 4. Display the gross pay in a pop-up window.
This is an example of an algorithm, which is a set of well-defined, logical steps that
must be taken to perform a task. An algorithm that is written out in this manner, in
plain English statements, is called pseudocode. (The word pseudo means fake, so
pseudocode is fake code.) The process of informally writing out the steps of an algo-
rithm in pseudocode before attempting to write any actual code is very helpful when
25
35. Introduction to Computers and Programming
you are designing a program. Because you do not have to worry about breaking any
syntax rules, you can focus on the logical steps that the program must perform.
Flowcharting is another tool that programmers use to design programs. A flowchart
is a diagram that graphically depicts the steps of an algorithm. Figure 28 shows how
you might create a flowchart for the wage-calculator algorithm. Notice
that there are three types of symbols in the flowchart: ovals, parallelograms, and a
rectangle. Each of these symbols represents a step in the algorithm, as described here:
• The ovals, which appear at the top and bottom of the flowchart, are called
terminal symbols. The Start terminal symbol marks the program’s starting point
and the End terminal symbol marks the program’s ending point.
• Parallelograms are used as input symbols and output symbols. They represent
steps in which the program reads input or displays output.
• Rectangles are used as processing symbols. They represent steps in which the
program performs some process on data, such as a mathematical calculation.
End
Start
Calculate the gross pay as the
number of hours worked
times the hourly pay rate
Get the hours worked
from the appropriate
TextBox
Display the gross pay
in a pop-up window
Get the hourly pay rate
from the appropriate
TextBox
Figure 28 Flowchart for the wage-calculator program
The symbols are connected by arrows that represent the “flow” of the program. To
step through the symbols in the proper order, you begin at the Start terminal and fol-
low the arrows until you reach the End terminal.
4. Write the Code
Once you have created a program’s GUI and designed algorithms for the program’s
tasks, you are ready to start writing code. During this process, you will refer to
the pseudocode or flowcharts that you created in Step 3 and use Visual Studio to
write C# code.
26
36. Introduction to Computers and Programming
5. Correct Syntax Errors
You previously learned in this chapter that a programming language such as C# has
rules, known as syntax, that must be followed when writing a program. A language’s
syntax rules dictate things such as how key words, operators, and punctuation char-
acters can be used. A syntax error occurs if the programmer violates any of these
rules. If the program contains a syntax error or even a simple mistake such as a mis-
spelled key word, the program cannot be compiled or executed.
Virtually all code contains syntax errors when it is first written, so the programmer
will typically spend some time correcting these. Once all the syntax errors and simple
typing mistakes have been corrected, the program can be compiled and translated
into an executable program.
4. Test the Program and Correct Logic Errors
Once the code is in an executable form, you must then test it to determine whether
any logic errors exist. A logic error is a mistake that does not prevent the program
from running but causes it to produce incorrect results. (Mathematical mistakes
are common causes of logic errors.) If the program produces incorrect results, the
programmer must debug the code. This means that the programmer finds and
corrects logic errors in the program. Sometimes, during this process, the program-
mer discovers that the program’s original design must be changed. In this event, the
program development cycle starts over and continues until no errors can be found.
Checkpoint
39 List the six steps in the program development cycle.
40 What is an algorithm?
41 What is pseudocode?
42 What is a flowchart?
43 What do each of the following symbols mean in a flowchart?
• Oval
• Parallelogram
• Rectangle
Getting Started with the Visual
Studio Environment
CONCEPT: Visual Studio and Visual C# Express consist of tools that you use
to build Visual C# applications. The first step in using Visual C# is
learning about these tools.
To follow the tutorials in this text, and create Visual C# applications, you will need to in-
stall either Visual Studio 2010 or Visual C# 2010 Express on your computer. Visual Studio
2010 is a professional integrated development environment (IDE), which means that it
provides all the necessary tools for creating, testing, and debugging software. It can be used
to create applications not only with Visual C#, but also with other languages such as Visual
Basic and C++. If you are using a school’s computer lab, there’s a good chance that Visual
Studio 2010 has been installed.
8
27
37. Introduction to Computers and Programming
If you do not have access to Visual Studio 2010, you can install Visual C# 2010 Express,
a free programming environment that is streamlined for Visual C# development.
It does not matter whether you are using Visual Studio 2010 or Visual C# 2010 Express.
Both products look very similar and work in a similar manner. When there are differ-
ences, the text will alert you. To keep things simple, this text will use the term Visual
Studio to refer to either Visual Studio 2010 or Visual C# 2010 Express. When you are
instructed to use Visual Studio to perform some task, use the system that is installed on
your computer.
Visual Studio is a customizable environment. If you are working in your school’s com-
puter lab, there’s a chance that someone else has customized the programming environ-
ment to suit his or her own preferences. If this is the case, the screens that you see may not
match exactly the ones shown in this text. For that reason it’s a good idea to reset the pro-
gramming environment before you create a Visual C# application. Tutorial 1 guides you
through the process.
Tutorial 1:
Starting Visual Studio and Setting Up the Environment
Step 1: Find out from your instructor whether you are using Visual Studio 2010 or Visual
C# 2010 Express. Then, click the Start button, open the All Programs menu,
and perform one of the following:
• If you are using Visual Studio, open the Microsoft Visual Studio 2010
program group and then execute Visual Studio 2010.
• If you are using Visual C# 2010 Express, open the Microsoft Visual
Studio 2010 Express program group and then execute Visual C# 2010
Express.
Step 2: Figure 29 shows the Visual Studio environment. The screen shown in the
figure is known as the Start Page. By default, the Start Page is displayed when
you start Visual Studio, but you may not see it because it can be disabled.
Notice the checkbox in the bottom left corner of the Start Page that reads Show
page on startup. If this box is not checked, the Start Page will not be displayed
when you start Visual Studio. If you do not see the Start Page, you can always
display it by clicking View on the menu bar at the top of the screen and then
clicking Start Page.
NOTE: If you are using Visual Studio rather than Visual C# Express, the first
time you run the software, you will see a window entitled Choose Default
Environment Settings. Select Visual C# Development Settings from the list
and click the Start Visual Studio button.
28
38. Introduction to Computers and Programming
Step 3: This step is applicable only if you are using Visual Studio. If you are using Vi-
sual C# Express, skip to Step 4. In a school computer lab, it is possible that the
Visual Studio environment has been set up for a programming language other
than Visual C#. To make sure that Visual Studio looks and behaves as described
in this text, you should make sure that Visual C# is selected as the programming
environment. Perform the following:
• As shown in Figure 30, click Tools on the menu bar and then click Import
and Export Settings....
• On the screen that appears next, select Reset all settings and click the Next >
button.
• On the screen that appears next, select No, just reset settings, overwriting my
current settings, and then click the Next > button.
• The window shown in Figure 31 should appear next. Select Visual C#
Development Settings and then click the Finish button.
• After a moment you should see a Reset Complete window. Click the Close
button and continue with the next step in the tutorial.
Step 4: Now you will reset Visual Studio’s window layout to the default configura-
tion. As shown in Figure 32, click Window on the menu bar and then
click Reset Window Layout. Next you will see a dialog box asking Are you
sure you want to restore the default window layout for the environment?
Click Yes.
Figure 29 Visual Studio Start Page
29
39. Introduction to Computers and Programming
Figure 30 Selecting Tools and then Import and Export Settings ...
Figure 31 Selecting Visual C# Development Settings
The Visual Studio environment is now set up so you can follow the remaining
tutorials. If you are working in your school’s computer lab, it is probably a
good idea to go through these steps each time you start Visual
Studio. If you are continuing with the next tutorial, leave Visual Studio
running. You can exit Visual Studio at any time by clicking File on the menu
bar and then clicking Exit.
30
40. Tutorial 2:
Starting a New Visual C# Project
Step 1: If Visual Studio is not already running, start it as you did in Tutorial 1.
Step 2: If you are using Visual Studio 2010: Click File on the menu bar at the top of
the screen, then select New, and then select Project. After doing this, the New
Project window shown in Figure 33 should be displayed.
Introduction to Computers and Programming
Figure 32 Resetting the window layout
Starting a New Project
Each Visual C# application that you create is called a project. When you are ready to cre-
ate a new application, you start a new project. Tutorial 2 leads you through the steps of
starting a new Visual C# project.
Make sure
Visual C# is
selected
1
Select Windows
Forms Application
2
Figure 33 The New Project window
31
41. Introduction to Computers and Programming
If you are using Visual C# 2010 Express: Click File on the menu bar at the
top of the screen and then select New Project. After doing this, a New Project
window similar to Figure 33 should be displayed. (With Visual C# Express, the
window will have fewer items than shown in the figure.)
Step 3: At the left side of the window, under Installed Templates, make sure Visual C#
is selected. (If you are using Visual C# Express, that will be the only choice.)
Then, select Windows Forms Application, as shown in Figure 33.
Step 4: At the bottom of the New Project window, you see a Name text box. This is
where you enter the name of your project. The Name text box will be autom
atically filled in with a default name. In Figure 33 the default name is Wind-
owsApplication1. Change the project name to My First Project, as shown in
Figure 34.
Change the project name to
My First Project
Figure 34 Changing the project name to My First Project
If you are using Visual Studio 2010: Just below the Name text box you will see
a Location text box and a Solution name text box.
• The Location text box shows where a folder will be created to hold the proj-
ect. If you wish to change the location, click the Browse button and select the
desired location.
Step 5: Click the OK button to create the project. It might take a moment
for the project to be created. Once it is, the Visual Studio environment should
appear, similar to Figure 35. Notice that the name of the project, My First Pro-
ject, is displayed in the title bar at the top of the Visual Studio window.
Leave Visual Studio running and complete the next tutorial.
NOTE: You will create a lot of Visual C# projects. As you do, you
will find that default names such as WindowsApplication1 do not help
you remember what each project does. Therefore, you should always
change the name of a new project to something that describes the project’s
purpose.
• A solution is a container that holds a project, and the Solution name text
box shows the name of the solution that will hold this project. By default,
the solution name is the same as the project name. For all the projects that
you create in this text, you should keep the solution name the same as the
project name.
32
42. Introduction to Computers and Programming
Tutorial 3:
Saving and Closing a Project
As you work on a project, you should get into the habit of saving it often. In this tutorial
you will save the My First Project application and then close it.
Step 1: Visual Studio should still be running from the previous tutorial. To save the proj-
ect that is currently open, click File on the menu bar and then select Save All.
If you are using Visual C# 2010 Express: The first time you save a project, the
Save Project window will appear, as shown in Figure 36.
• The Name text box shows the project name that you entered when you
created the project. Leave this unchanged.
Figure 35 The Visual Studio environment with a new project open
Click here to save the project
Figure 36 The Save Project window in Visual C# 2010 Express
33
43. Introduction to Computers and Programming
• The Location text box shows where a folder will be created on your system to
hold the project. If you wish to change the location, click the Browse button
and select the desired drive and folder.
• A solution is a container that holds a project, and the Solution name text box
shows the name of the solution that will hold this project. By default, the
solution name is the same as the project name. For all the projects that
you create in this text, you should keep the solution name the same as the
project name.
Click the Save button to save the project. (If possible, leave Visual Studio
running so you can complete the next tutorial.)
Step 2: To close the project, click File on the menu bar and then click Close Solution.
The Visual Studio Environment
The Visual Studio environment consists of a number of windows that you will use on a
regular basis. Figure 37 shows the locations of the following windows that appear within
the Visual Studio environment: the Designer window, the Solution Explorer window, and
the Properties window. Here is a brief summary of each window’s purpose:
• The Designer Window
You use the Designer window to create an application’s graphical user interface.
The Designer window shows the application’s form and allows you to visually
design its appearance by placing the desired controls that will appear on the form
when the application executes.
• The Solution Explorer Window
A solution is a container for holding Visual C# projects. (We discuss solutions in
greater detail in a moment.) When you create a new C# project, a new solution is
automatically created to contain it. The Solution Explorer window allows you to
navigate among the files in a Visual C# project.
• The Properties Window
A control’s appearance and other characteristics are determined by the control’s
properties. When you are creating a Visual C# application, you use the Properties
window to examine and change a control’s properties.
Remember that Visual Studio is a customizable environment. You can move the var-
ious windows around, so they may not appear in the exact locations shown in
Figure 37 on your system.
Displaying the Solution Explorer and Properties Windows
If you do not see the Solution Explorer or the Properties window, you can follow these
steps to make them visible:
• If you do not see the Solution Explorer window, click View on the menu bar. On
the View menu, click Solution Explorer. (In Visual C# Express, click View, Other
Windows, Solution Explorer.) You can also press ∏+W, and then press S on the
keyboard.
34
44. Introduction to Computers and Programming
• If you do not see the Properties window, click View on the menu bar. On the View
menu, click Properties. (In Visual C# Express, click View, Other Windows,
Properties.) You can also press ∏+W and then press P on the keyboard.
Using Auto Hide
Many windows in Visual Studio have a feature known as Auto Hide. When you see the
pushpin icon in a window’s title bar, as shown in Figure 38, you know that the window
has Auto Hide capability. You click the pushpin icon to turn Auto Hide on or off for a
window.
Designer window
Properties window
Solution Explorer
window
Figure 37 The Designer window, Solution Explorer window, and Properties window
Pushpin icon
Figure 38 Auto Hide pushpin icon
35
45. Introduction to Computers and Programming
The Menu Bar and the Standard Toolbar
You’ve already used the Visual Studio menu bar several times. This is the bar at the top of the
Visual Studio window that provides menus such as File, Edit, View, Project, and so forth. As
you progress through this text, you will become familiar with many of the menus.
Below the menu bar is the standard toolbar. The standard toolbar contains buttons that
execute frequently used commands. All commands that are displayed on the toolbar may
also be executed from a menu, but the standard toolbar gives you quicker access to them.
Figure 40 identifies the standard toolbar buttons that you will use most often, and Table
3 gives a brief description of each.
Solution Explorer tab
Properties tab
Figure 39 The Solution Explorer and Properties windows hidden
When Auto Hide is turned on, the window is displayed only as a tab along one of the
edges of the Visual Studio environment. This feature gives you more room to view your
application’s forms and code. Figure 39 shows how the Solution Explorer and
Properties windows appear when their Auto Hide feature is turned on. Notice the tabs
that read Solution Explorer and Properties along the right edge of the screen. (Figure 39
also shows a Team Explorer tab. You might see this tab if you are using Visual Studio
2010.)
36
46. Introduction to Computers and Programming
Open
File
Add New
Item
New
Project Save All
Save
Copy
Solution
Configuration
Undo
Redo
Cut Paste
Navigate
Backward
Start
Debugging
Navigate
Forward
Find
Properties
Window
Start
Page
Object
Browser
Toolbox
Solution
Explorer
Figure 40 Visual Studio toolbar buttons
The Toolbox
The Toolbox is a window that allows you to select the controls that you want to use in an
application’s user interface. When you want to place a Button, Label, TextBox, or other
control on an application’s form, you select it in the Toolbox. You will use the Toolbox
extensively as you develop Visual C# applications.
The Toolbox typically appears on the left side of the Visual Studio environment. If the
Toolbox is in Auto Hide mode, its tab will appear as shown in Figure 41. Figure 42 shows
the Toolbox opened, with Auto Hide turned off.
Table 3 Visual Basic toolbar buttons
Toolbar Button Description
New Project Starts a new project
Add New Item Adds a new item such as a form to the current project
Open File Opens an existing file
Save Saves the file named by filename
Save All Saves all the files in the current project
Cut Cuts the selected item to the clipboard
Copy Copies the selected item to the clipboard
Paste Pastes the contents of the clipboard
Undo Undoes the most recent operation
Redo Redoes the most recently undone operation
Navigate Backward Moves to the previously active tab in the Designer window
Navigate Forward Moves to the next active tab in the Designer window
Start Debugging Starts debugging (running) your program
Solution Configurations Configures your project’s executable code
Find Searches for text in your application code
Solution Explorer Opens the Solution Explorer window
Properties Window Opens the Properties window
Object Browser Opens the Object Browser window
Toolbox Opens the Toolbox window, displaying, for example, visual controls
you can place on Windows forms
Start Page Displays the Visual Studio Start Page
37
47. Introduction to Computers and Programming
Figure 42 The Toolbox opened (Auto Hide turned off)
Toolbox tab
Figure 41 The Toolbox tab (Auto Hide turned on)
NOTE: If you do not see the Toolbox or its tab along the side of the Visual Studio
environment, click View on the menu bar and then click Toolbox. (In Visual C#
Express, click View on the menu bar, then click Other Windows, and then click
Toolbox.)
The Toolbox is divided into sections, and each section has a name. In Figure 42 you can
see the All Windows Forms and Common Controls sections. If you scroll the Toolbox,
you will see many other sections. Each section can be opened or closed.
38
48. Introduction to Computers and Programming
If you want to open a section of the Toolbox, you simply click on its name tab. To close
the section, click on its name tab again. In Figure 42, the Common Controls section is
open. You use the Common Controls section to access controls that you frequently need,
such as Buttons, Labels, and TextBoxes. You can move any section to the top of the list by
dragging its name with the mouse.
Using ToolTips
A ToolTip is a small rectangular box that pops up when you hover the mouse pointer over
a button on the toolbar or in the Toolbox for a few seconds. The ToolTip box contains
a short description of the button’s purpose. Figure 43 shows the ToolTip that appears when
the cursor is left sitting on the Save All button. Use a ToolTip whenever you cannot
remember a particular button’s function.
Figure 43 Save All ToolTip
Docked and Floating Windows
Figure 42 shows the Toolbox, Solution Explorer, and Properties windows when they are
docked, which means they are attached to one of the edges of the Visual Studio window.
Alternatively, the windows can be floating. You can control whether a window is docked or
floating as follows:
• To change a window from docked to floating, right-click its title bar and select
Float.
• To change a window from floating to docked, right-click its title bar and select
Dock.
Figure 44 shows Visual Studio with the Toolbox, Solution Explorer, and Properties win-
dows floating. When a window is floating, you can click and drag it by its title bar around
the screen. You may use whichever style you prefer—docked or floating. When windows
are floating, they behave as normal windows. You may move or resize them to suit your
preference.
NOTE: A window cannot float if its Auto Hide feature is turned on.
TIP: Remember, you can always reset the window layout by clicking Window on
the menu bar and then selecting Reset Window Layout. If you accidentally close the
Designer window, the Solution Explorer window, or the Properties window, you can
use the View menu to redisplay them.
39
49. Introduction to Computers and Programming
Figure 44 Toolbox, Solution Explorer, and Properties windows floating
Projects and Solutions
As you learn to program in Visual C#, you will see the terms project and solution used
often. These terms do not mean the same thing, but they are sometimes used interchange-
ably. Let’s briefly discuss the difference between a project and a solution.
Each Visual C# application that you create is called a project. A Visual C# project consists
of several files. You can think of a project as a collection of files that belong to a single
application.
A solution is a container that holds one or more Visual C# projects. If you are developing
applications for a large organization, you might find it convenient to store several related
projects together in the same solution.
Although it is possible for a solution to hold more than one project, each project that you
will create in this text will be saved in its own solution. Each time you create a new proj-
ect, you will also create a new solution to hold it. Figure 45 illustrates this concept. Typi-
cally, the solution will be given the same name as the project.
Solution
Project
Files Belonging
to the Project
Figure 45 Solution and project organization
40
50. Introduction to Computers and Programming
Project name
Solution name This is where the solution folder will be created
Figure 46 Specifying the project name, solution name, and location
Project folder
Solution file
Figure 47 Contents of the My First Project solution folder
Typical Organization of Solutions
and Projects on the Disk
When you create a new project, you specify the project’s name, the solution’s name,
and a location on the disk where the solution should be stored. If you are using Visual
Studio, you specify this information at the bottom of the New Project window, as
shown in Figure 46. If you are using Visual C# Express, you specify this information in
the Save Project window (shown previously in Figure 36) the first time you save the
project.
Let’s use Figure 46 to see an example of how the files for the My First Project solution and
project will be organized on the disk. Notice that in Figure 46, the following
location is shown for the solution:
C:UsersTonyDocumentsVisual Studio 2010Projects
On your system, the location will not be exactly the same as this, but it will be something
similar. At this location, a solution folder named My First Project will be created. If we
use Windows to look inside that folder, we will see the two items shown in Figure 47.
Notice that one of the items is another folder named My First Project. That is the project
folder, which contains various files related to the project. The other item is the solution
file. In Windows, you can double-click the solution file to open the project in Visual
Studio.
41
51. Introduction to Computers and Programming
Opening an Existing Project
If Visual Studio is already running, you can perform the following steps to open an existing
project:
• Click File on the Visual Studio menu bar, then select Open, and then select
Project/Solution....
• The Open Project window will appear. Navigate to the desired solution folder, select
the solution file, and click Open.
In Visual C# Express, perform the following steps to open an existing project:
• Click File on the Visual Studio menu bar and then select Open Project....
• The Open Project window will appear. Navigate to the desired solution folder, select
the solution file, and click Open.
Tutorial 4:
Opening an Existing Project
In this tutorial you will reopen the My First Project application that you created in
Tutorial 2.
Step 1: Visual Studio should still be running from the previous tutorial. Perform one of
the following operations to reopen My First Project:
If you are using Visual Studio:
Click File on the menu bar; select Open and then select Project/Solution.... The
Open Project window will appear. Navigate to the My First Project solution,
select the solution file, and click the Open button.
If you are using Visual C# Express:
Click File on the menu bar, and then select Open Project.... The Open Project
window will appear. Navigate to the My First Project solution, select the solu-
tion file, and click the Open button.
After performing this step, My First Project should be opened. If you plan to
complete the next tutorial, leave Visual Studio running with My First Project
opened.
Displaying the Designer (When It Does Not
Automatically Appear)
Sometimes when you open an existing project, the project’s form will not be automatically
displayed in the Designer. Figure 48 shows an example of the Visual Studio environment
with an opened project but no form displayed in the Designer. When this happens, perform
the following steps to display the project’s form in the Designer:
• As shown in Figure 49, right-click Form1.cs in the Solution Explorer.
• Click View Designer in the pop-up menu.
Accessing the Visual Studio Documentation
You can access the documentation for Visual Studio by Clicking Help on the menu bar, and
then selecting View Help. (Or, you can press ∏+!, and then press V on the keyboard.)
This launches your Web browser and opens the online Microsoft Developer Network
42
52. Introduction to Computers and Programming
Figure 48 A Project opened with no form displayed in the Designer
1
Right-click Form1.cs in
the Solution Explorer
2 Click View Designer
Figure 49 Using the Solution Explorer to open a form in the Designer
(MSDN) library. The MSDN library provides complete documentation for Visual C# as
well as the other programming languages included in Visual Studio. You will also find code
samples, tutorials, articles, and access to Microsoft Channel 9 Videos.
43
53. Introduction to Computers and Programming
Tutorial 5:
Getting Familiar with the Visual Studio Environment
This exercise will give you practice interacting with the Solution Explorer window, the
Properties window, and the Toolbox.
Step 1: If Visual Studio is still running on your computer from the previous tutorial,
continue to Step 2. If Visual Studio is not running on your computer, repeat the
steps in Tutorial 4 to open My First Project.
Step 2: Practice turning the Auto Hide feature on and off for the Solution Explorer win-
dow, the Properties window, and the Toolbox. Recall from our previous discus-
sion that clicking the pushpin icon in each window’s title bar turns Auto Hide
on and off. When you are finished practicing, make sure Auto Hide is turned off
for each of these windows. Your screen should look like Figure 42.
Step 3: Practice floating and docking the Solution Explorer window, the Properties
window, and the Toolbox. Recall from our previous discussion that you can
make any of these windows float by right-clicking its title bar and selecting
Float. You dock a floating window by right-clicking its title bar and selecting
Dock.
Step 4: The Toolbox, Solution Explorer, and Properties windows each have a Close
button ( ) in their upper-right corner. Close each of these windows by clicking
their Close button.
Step 5: Do you remember which buttons on the toolbar restore the Solution Explorer,
Properties window, and Toolbox? If not, move your mouse cursor over any but-
ton on the toolbar and leave it there until the ToolTip appears. Repeat this pro-
cedure on different buttons until you find the ones whose ToolTips read
Solution Explorer, Properties Window, and Toolbox. (Refer to Figure 40 and
Table 3 for further assistance.)
Step 6: Click the appropriate buttons on the toolbar to restore the Solution Explorer,
the Properties window, and the Toolbox.
Step 7: Exit Visual Studio by clicking File on the menu bar and then clicking Exit. You
may see a dialog box asking you if you wish to save changes to a number of
items. Click Yes.
Checkpoint
44 Briefly describe the purpose of the Solution Explorer window.
45 Briefly describe the purpose of the Properties window.
46 Briefly describe the purpose of the standard toolbar.
47 What is the difference between the toolbar and the Toolbox?
48 What is a ToolTip?
49 What is a project?
50 What is a solution?
44
54. Introduction to Computers and Programming
Key Terms
algorithm
American Standard Code for
Information Interchange (ASCII)
application software
assembler
assembly language
Auto Hide
binary
binary digit
binary numbering system
bit
Button
byte
class
code
command line interface
compact disc (CD)
compiler
console interface
controls
central processing unit (CPU)
debug
Designer window
digital
digital data
digital device
disk drive
docked (window)
digital versatile disc (DVD)
End lterminal
ENIAC
event driven
executing
fetch-decode-execute cycle
fields
floating (window)
floating-point notation
floppy disk drive
flowchart
Form
graphical user interface (GUI)
hardware
high-level languages
input
input device
input symbols
instruction set
integrated development
environment (IDE)
interpreter
keywords
Label
logic error
low-level language
machine language
main memory
methods
microprocessors
mnemonics
.NET Framework
object oriented
operating system
operators
output
output device
output symbols
picture element
pixel
processing symbols
program
program development cycle
programmer
project
project folder
properties
Properties window
pseudocode
random-access memory (RAM)
reserved words
running
samples
secondary storage
software
software developer
software development tools
solution
Solution Explorer window
solution file
solution folder
source code
standard toolbar
start terminal
statements
syntax
syntax error
system software
terminal symbol
TextBox
Toolbox
ToolTip
two’s complement
Unicode
45
56. looked upon as the highest virtue, the slave is regarded as the ne
plus ultra—a man who, for want of a contempt of death, allows
himself to be put in chains; and it is this vice which is so difficult to
be forgiven. This way of looking at the subject is further
strengthened by the boundless feeling of aristocracy which
distinguishes the Tartars, whether settled or nomad, in which not
even the wildest Tories or the proudest marquis of the Faubourg St.
Germain can surpass them—a feeling which is entertained not only
against the foreign Iranian, but even the native Tadjiks, the eldest
inhabitants of the land.
It will be understood that it is only the moral stigma of slavery which
the freedman has to suffer from. In his civil rights he is as well
protected as any one else. Thus, as the Oriental is even more a
creature of habit than we are, I found it very easy to understand
how the Persian soon finds himself completely at home in Turkestan,
which country he once so despised and dreaded, and dwells
contentedly in a foreign land, only occasionally solacing himself with
a visit to his relations or to the shrine of some Shiite saint in Iran.
Unfortunately, it is the material comfort and prosperity of the slave
which the Central Asiatic, like other Mohammedans, alleges in his
defence, when we express our abhorrence of the disgraceful traffic
in human beings. As in Turkestan, so in Turkey we may often hear
this argument:—"The sons and daughters of the wild Circassians
were in their native land poor people, who in their free mountains
could hardly get bread enough to eat; here with us they become rich
government officials, pashas, nay, even princesses, whose powerful
influence affects the policy of government." They further point out
how kindly the slaves are treated in the houses of persons of
distinction, where they are put on the same footing as the members
of the family. But they forget that these cases are exceptional, and
that such good fortune depends for the most part on the personal
beauty of the favoured few. What becomes of the greater number,
whose charms are not such as to gain the favour of their master?
What shall we say of this majority, exposed as they are to the
57. oppression and cruelty of a tyrannical master, and constantly
employed in the hardest labour?
Such things are of course not taken into account, any more than the
original cruelty of the slave merchant, who tears his victims from
their homes and their friends. On the banks of the Bosphorus, as on
those of the Oxus, few persons care to picture to their minds the
horrors of that first moment of separation. How many orphans, how
many widows, how many aged and helpless parents, are left behind
to wring their hands in sorrow for their bread-winner, who is carried
into captivity! It is impossible to count them, it is impossible to
describe the miserable condition of so many villages and districts
which are exposed to the terrible scourge of the slave trade. The
traveller in those regions stumbles at every step over the most
melancholy traces of the devastation which it causes. However
certain he may feel of the splendid destiny which awaits this or that
individual captive, he must still exclaim: "This is the most execrable
occupation that has ever defiled the hands of man, and its
suppression is the first and holiest duty which our western
civilisation has to perform for the cause of humanity!"
The suppression of the slave trade in Central Asia is, moreover, much
easier than many might at first sight suppose. The root of the evil is
to be sought, not so much in the Turkomans as in the inhabitants of
the cities. All nomad tribes were and are ready for such a trade, if
they only find settled tribes who will buy their captives of them. The
Bedouins of the Arabian desert could never addict themselves much
to the traffic, inasmuch as the markets of the surrounding cities
were closed by the religion of Islam against the sale of their booty.
In the same way the Turkomans would soon abandon the practice, if
the sale of Persians, Afghans, &c., in the Khanats were declared
illegal. The Djemshidis, the Firuzkuhis, and Hezares, afford the
strongest proof of this. As the transport of their captives to Bokhara
is rendered unsafe by the intermediate Turkoman tribes, while at the
same time their sale is forbidden in the Afghan town of Herat, they
have either to suppress their slave-trading propensities altogether, or
58. come to a compromise with the Turkomans, much to the advantage
of the latter.
Sultan Murad Mirza, an enlightened prince, and the governor of
Khorassan, once expressed to me his surprise that England, which
spends so many thousands in checking the slave trade in African
waters, can look on unconcernedly while the same trade in the
middle of Asia lays waste such a country, whose ancient civilisation
was of profit to Europe itself. In like manner I, too, cannot conceal
my astonishment at the apathy which Europe, and especially that
State whose flag is in the East ever the harbinger of the dawn of a
newer, a happier era, has displayed on this question. Sentimental
newspaper writers, in their political rhapsodies, may yet for a long
time take under their protection the feelings of independence of
many a savage Asiatic tribe, to whom freedom means nothing more
than anarchy, plunder, and murder. But the dreams of Rousseau
have had their day, and we can with the fullest confidence say, that
whenever Europe shows herself in the East, whether in the peaceful
garb of the missionary, or in the terrible panoply of her warlike
power, she brings only blessings in her train, and scatters the seeds
of a new order of things. The more light is poured from the West
upon the East, the sooner will the evil customs of the old world be
eradicated, and our brother men be made happier.
59. CHAPTER XIV.
PRODUCTIVE POWER OF THE THREE OASIS
COUNTRIES OF TURKESTAN.
In arguing about the Russian conquest of Central Asia, we are wont
to say that the Court of St. Petersburg, in those far-reaching
schemes which she pursues towards the Hindu-Khush with so much
toil, at so heavy a cost, seeks some richer recompense than is to be
found on the shores of the Yaxartes and the Oxus. Well; it is true
that Russia's policy does not confine itself to the possession of the
plains of Bokhara, Khokand, and Khiva. But in the meantime let us
not undervalue the immediate gain of these conquests. It is right
that we should learn the comparative worth of the three Khanats,
the nature and extent of their produce, both as it is, and as with
proper management it might become.
The very name of "oasis countries" contributes towards creating an
impression, that the inhabited part of Turkestan must be
unimportant as regards productive power; add to this the poverty
and the extremely primitive and simple mode of life of its
inhabitants, and it is not surprising that the great distance and the
consequent want of knowledge should have begotten and spread
erroneous notions. The natives themselves, as well as oriental
travellers and geographers, such as Idrisi, Ibni Haukal, Ebulfeda, and
the learned Prince Baber, fall into the opposite extreme, by
representing Turkestan as the richest country on the face of the
globe, India alone excepted. This opinion prevailed in former times,
[21]
not only throughout Western Asia, but even very lately I have
met with it in several localities, and never felt more astonished than
when I heard the egotistic Persian eloquently praising the wealth of
Turkestan, a country he looks upon with deadly hatred and aversion.
60. As for ourselves, we will try to form as far as possible an impartial
estimate, although we must maintain at the outset, that Turkestan
by far surpasses the known parts of European and Asiatic Turkey,
Afghanistan and Persia, both in the wealth and variety of its
productions; nay, that it might be difficult to find in Europe,
flourishing as it is, and rich in every blessing, a territory that would
rival the oasis countries of Turkestan.
The great variety of productions is to be ascribed essentially to the
climate of the countries bordering the Oxus and Yaxartes. It is
neither harsh, nor could it exactly be termed mild. On the average it
corresponds to the climate of Central Europe, though it must be
remarked, that the winter is far more severe on the shores of the
Sea of Aral and in the mountainous parts of Khokand, and the
summer, on the contrary, much warmer in those districts that lie to
the south, and often almost tropical in the immediate neighbourhood
of the great sandy deserts. The Oxus is frozen over every winter,
from Kerki and Tchardshuy to its mouth; in Kungrad, Khodja Ili, and
on the right bank, where the Karakalpaks dwell, the winter is
generally very severe; the snow lies often for weeks on the ground,
and tempestuous north winds (Ayamudjiz) are not unfrequent.
Under such conditions there can be no question of a mild climate,
and yet in Khiva I have found the heat unbearable as early as the
beginning of June, while in August, near Kerki and Belkh, it was
more sultry and oppressive, even in the shade, than is the case in
really tropical countries. This great variation in the climate produces
corresponding local differences in the vegetation of even a small
extent of country. Thus, for instance, the cotton of Yengi Üergendj is
far better than that in the more northern districts, and the silk of
Hezaresp is considered throughout the Khanat of Khiva to be of first-
rate quality. Görlen produces the finest rice, and the finest fruit is
found in the environs of Khiva, which lies farther south. In Bokhara
and in Khokand we see the same effects produced by the climate,
and hence the reason why each of the three Khanats contains, on a
comparatively small area, such various and manifold productions, as
61. are usually met with only in larger countries, which lie between
several zones.[22]
The extraordinary productiveness of the soil is to be ascribed partly
to the "blessed" rivers, so-called by the natives, which intersect the
oasis-countries, and partly to the quality of the soil. Of these rivers
the Oxus is the most important. From its fertilizing influence upon
the land it may be compared to the Nile; although, when used as
drinking-water, the latter still surpasses it in its pleasantness to the
taste. Next comes the Zerefshan, whose name, "Scatterer of Gold,"
sufficiently indicates the blessing it scatters over its shores. Nor are
the smaller rivers, such as the Shehr Sebz and the tributaries of the
Yaxartes, of less importance. When we finally add, that the irrigation
of the fields is carried on with as much care, and much more ease,
than in other parts of Western Asia, we shall cease to marvel any
longer at the rich resources of the soil, however grand and important
they may still appear.
I have already noticed in my "Travels in Central Asia" that the
irrigation is carried on—firstly, by natural canals, called arna, which
are formed by the irregular course of the Oxus; secondly, by yaps,
i.e., smaller artificial canals, by which every village and colony is
surrounded and intersected. In all places of any importance there is
a high official, called Mirab (prince or warden of the water), who
inspects the various aqueducts, and orders them every spring to be
freed from the accumulated sand. During the winter the sluice-gates
of all the principal "arnas" are closed as a protection against the
inundations which naturally follow the breaking up of the ice. The
cleaning of the canals takes place at the beginning of April, and the
great object in view is to make them constantly deeper and
narrower. The sand that is taken out is heaped up on both sides of
the bank, which have thus for miles the appearance of
intrenchments, and with their cooling shade protect the precious
water from the burning rays of the summer's sun. To the general
purposes of communication, however, these intrenched ditches are
very prejudicial, although of real advantage to agriculture. Hence,
the more expensive kahriz—subterranean canals—in Persia, are far
62. more advantageous, and, moreover, preserve the water purer and
cooler. The yaps and arnas in Central Asia form great obstacles to
the traveller. Bridges are either very bad or altogether wanting. Let
the reader imagine the trouble and the dreadful loss of time
incurred, when a caravan with its heavily-laden camels has to cross
from ten to fifteen of such embanked canals in one day's march.
How prejudicial it is to the rivers to have so much water drawn off,
we see clearly in the Oxus. Formerly it flowed, no doubt, into the
Caspian Sea, now its embouchure is in the Sea of Aral,[23]
and this
great change in its watercourse must be ascribed, if not wholly, yet
in a great degree, to the evil of the many small canals.
It is difficult to decide which of the three Khanats is the most fertile,
especially now, when since the death of the much-lamented Conolly,
nobody is able to furnish a succinct account of the nature and
resources of the soil. To judge from all I have seen in my journey to
Samarkand, and learned from my fellow-travellers, of Khokand, the
native home of most of them, I should feel inclined to give the
preference to the Khanat of Khiva in point of vegetation. The two
other Khanats have more land under cultivation, but Khiva surpasses
them by far in the quantity and quality of its productions, with the
exception, perhaps, of fruit, which Bokhara furnishes in greater
variety, and of finer flavour. Bokhara also deserves the prize with
respect to all mineral productions; but the breeding of the finest
cattle and horses is the exclusive property of the nomads.
The land is measured by tanab (cord,—a tanab is equal to sixty
square yards), and in Khiva and Khokand consists of (1) Mülk,
freehold property, which is subject to the payment of taxes; (2)
Khanlik, arrear estates, i.e., such land which the Government has
either reclaimed and brought under cultivation, or which has
devolved upon it by confiscation and conquest. Of this land a third of
the net income is claimed by the State. (3) Yarimdji,[24]
all land that
belongs to the medresse (schools), mosques, or any religious
institutions, and which is liable to a fourth of the net income. The
Khanlik estates in each district are under the control of a certain
number of officials, called Müshürüb, who at the same time collect
63. the taxes. Church property, on the contrary, is under the
management of the mutevalis, as in other Islamitic countries.
The quality of the land in general may be judged best by my stating,
that the richest soil under cultivation produces one hundred batman
(one batman is equal to twenty-four pounds) on a tanab, and that of
least productive quality never less than sixty batman. And taking into
consideration that the cultivation of the ground here, as everywhere
in Asia, is done in the most negligent manner, and is in the highest
degree primitive, a competent judge can easily form an idea of the
great fertility of the soil.
It is impossible for me to say how many square miles of cultivated
land, or of land capable of cultivation, the three Khanats possess.
The frequent wars and unsettled times sufficiently explain the
numerous ruins of former flourishing colonies. Of the Khanat of
Khiva thus much at all events may be assumed, that the area of
territories laid waste and turned into deserts is larger than the land
at present under cultivation. With the exception of a few single
productions, with which the three Khanats carry on an export trade
among each other, and with Russia, only so much of the rest is
grown as is required for home consumption. There is no doubt that
not only might the quality of all present productions be essentially
improved, but also considerably multiplied.
A short survey of the productions of the three Khanats will help to
explain and confirm in detail all I have hitherto stated.
1. The Vegetable Kingdom.
Wheat and barley are the most important among the cereals grown
in the oasis countries of Turkestan. There are four kinds of wheat:—
1. Bukhara budayi (Bokhara wheat) is considered the finest; it has a
long, thin, and reddish grain, with a greenish top. Of this sort the
delicious bread is baked, in the preparation of which the town of
64. Bokhara excels, and which is famed far and wide under the name of
shirmaye (milk-marrow).
2. Tokmak bash (cuneiform top) has a round, thick grain; it is very
substantial, and most like our wheat. The best quality is found in
Khiva.
3. Kara süllü (black-haired) has a thin and dark-brown grain; it is
chiefly used as food for horses, not being of a particularly good
quality.
4. Yazlik (summer-fruit) takes a very short time to grow; it is
exceedingly light, and, when used, is mixed with other kinds of
wheat.
Barley is not so good in Central Asia as in Persia or Turkey. There is,
besides the usual sort, an inferior one, called karakalpak in Khiva,
which is here used, as everywhere in the East, as food for horses.
The average prices of all cereals are exceedingly low, as compared
with the countries of western Asia. The price of a Khiva batman of
the best wheat varies from two to three tenge (one tenge, seventy-
five cent.), whilst barley costs often less than one tenge, and seldom
more.
Rice is grown in enormous quantities, but it is far inferior to the
Herat or the excellent Shiraz rice, called tchampa and amberbuy
(amber perfume) in quality. It is more like the Egyptian, called in
Turkey dimyati (damietter), but would no doubt surpass the latter, if
cultivated with more care and attention.
Djügeri (holcus sorghum) is grown and consumed in far larger
quantities in the three Khanats than anywhere else in Asia. It is
eaten in a milky state, but when dry it is used as fodder, principally
for young colts, being less heating, and also more nourishing, than
barley, from the quantity of saccharine matter it contains. Bread is
made of it, either alone or mixed with wheat.
Mekke djügeri (Turkish wheat) never grows higher than a small
span's length. Two kinds of it are found, one with a yellowish, the
65. other with a red, small grain. It is never dried, and always either
eaten in its milky state or used as fodder.
Tari (groats) is an important article of consumption in Central Asia,
and is therefore much grown. There are several sorts.
Besides the well-known kinds of pulse, such as peas (burtshak),
beans (lubie), lentils (jasmuk), &c., there are several others which
we do not know; as for instance, the konak, which has smaller but
thicker seeds, and a lower shrub than our lentil; mash, rather larger
than millet, of a brownish colour, and several others, which are of no
interest to the general reader.
Of oil-plants, I must mention first of all the kündshi sesame, which
thrives very well, and provides the Khanats amply with oil for
cooking and burning. Then there is the zigir, a plant similar to millet,
which bears on one stalk several fruits, which are like apples, and
the yellow seeds in which are not bigger than poppy-seeds. This oil
is fit in food, especially in pastry. Then the djigit, the seeds of the
cotton-capsule, the oil of which, however, is not fit for food. Kender
(hemp), of which an inferior sort of linen is made, and which also
furnishes the very popular narcotic, called beng. Lastly, indau, a
small shrub, from the greenish seeds of which a bitter oil, and of a
disagreeable smell, is made, which is used as a medicine for
animals, and especially for camels.
Among the plants, which produce dye-drugs, the following are most
esteemed:—ruyan or boyak, an excellent species of madder, which
thrives in all three Khanats, and is exported in considerable
quantities to Russia. In the year 1835 this article was very little in
request, and in the year 1860 as many as 24,523 Russian pud
(883,000 English pounds) were imported.[25]
Isbarak or barak, whose
small yellow flowers, when dried and powdered, give a fine yellow
colour. Görtchük, a plant resembling clover, with small red flowers;
the leaves, when boiled, give a fine black colour. Buzgundjh, a plant
with a fruit similar to gall-nuts, only grows in southern Maymene,
and in the Badkhiz mountains, north of Herat, and is said to produce
the finest red colour; it fetches a high price in the place itself.
66. Although not belonging to the same class of plants, I must mention
here the terendjebin, a resinous and very sweet substance, which
grows on a thorn, called khari shutur (camel's thorn). The
terendjebin shows itself suddenly and quite unexpectedly towards
the end of the summer during the night, and has to be collected at
once in the early morning, before it grows hot. It resembles a gum,
is of a greyish white colour, exceedingly sweet, and can be eaten in
its raw state; in Central Asia it is made into shire (syrup), but in
Persia it is used in the sugar-manufactures of Meshed and Yezd.
As regards fruit, we find in the Khanats almost every species (with
the exception of fruits of the South) in great quantity, and of
excellent quality. A very considerable export trade is carried on in it
to Russia, and even to "rich" India. The Central Asiatic is not a little
proud of his superiority in this respect, in Asia the glory and value of
a country being determined by the quality of its water, air, and fruit.
Each of the three Khanats has in the latter its spécialité; Khiva is
distinguished for its melons and apples, Bokhara for its grapes and
peaches. It may be that some parts of Persia and Turkey surpass
Bokhara; but for melons, Khiva is unrivalled, not only in Asia, but I
feel inclined to say, throughout the world. No European can form an
idea of the sweet taste and aromatic flavour of this delicious fruit. It
melts in the mouth, and, eaten with bread, is the most wholesome
and refreshing food that nature affords.
The celebrated Nasrabadi melon alone, near Ispahan, reminds one,
though very feebly, of this fruit of Central Asia, unique in its kind.
There is a great variety of species. The principal summer melons are
the following:—1. Zamtche, which ripens earliest; it is round, of a
yellowish colour, and has a thin skin. 2. Görbek, of a greenish colour,
and with a white meat. 3. Babasheikhi is small, round, and with a
white meat. 4. Köktche. 5. Shirin Petchek, especially mellow and
sweet, of a small round shape. 6. Shekerpare. 7. Khitayi. 8.
Koknabat. 9. Aknabat. 10. Begzade.[26]
The winter melons are not
ripe until the beginning of October, but they keep the whole winter,
and are most palatable in February. There are the following kinds:—
67. 1. Karagulebi. 2. Kizilgulabi. 3. Beshek. 4. Payandeki. 5. Saksaul
Kavunu. These are mostly exported to Russia.
The Oxus chiefly contributes to render the melons of Central Asia so
incomparably excellent, since the finest quality thrives only on its
banks. The melons of Bokhara are very indifferent, and in quality
even inferior to those of Khokand.
Khanikoff mentions in his interesting work[27]
ten different kinds of
grapes he found in Bokhara. In Khiva I met with the following:—1.
Huseini, with oblong seeds and a thin skin, very sweet, and keeps
throughout the winter. 2. Meske, with large round seeds. 3. Sultani.
4. Khalide are ripe first of any. 5. Shiborgani. 6. Taifi. 7. Khirmani. 8.
Sayeke. All these different sorts of grapes grow on the level ground,
and are either made into shire (syrup) or dried for eating; wine
being made only by the Jews in Bokhara, and in a very small
quantity.
There are four sorts of apples grown, and that of Hezaresp may
boldly challenge the productions of our European horticulture.
The mulberry, too, is larger, more varied, and sweeter than ours, and
to this superiority we must, perhaps, ascribe the fact, that the silk of
Central Asia is better than the Italian and French, and that a certain
disease among silk-worms, common with us for many years, is there
quite unknown.
The rearing of silk-worms came originally from Chinese Tartary,
especially from Khoten, where, as M. Reinaud[28]
correctly remarks, it
was introduced in the first century of our era from the interior of
China. Silk stuffs of native manufacture were known in Bokhara in
pre-Islamitic times, according to the testimony of a certain
Manuscript,[29]
which treats of the ancient history of Bokhara. It is no
exaggeration to assert that the cultivation, spinning, and dyeing of
silk, is a still more primitive process in the three Khanats than in
China itself, where industrial progress, no doubt, effected many
changes, whilst here everything has remained as it was years ago.
The Khanat Bokhara supplies most of the raw silk; it is produced in
68. the capital, in Samarkand, and among the Lebab-Turkomans. Much
also comes from the Khanat of Khokand, in the neighbourhood of
Mergolan and Namengan. Khiva contributes but little, and this little is
inferior in quality to the productions of the other Khanats, though, as
competent judges have assured me, it is far superior to the silk of
Gilan and Mazendran, in Persia. The manipulation, however, is very
imperfectly performed. I was struck with the manner of winding off
the cocoons, which were placed in a cauldron of boiling water and
stirred with a broom, until a certain number of threads unwind
themselves, which are then wound round the broom. The dyeing is
almost exclusively in the hands of the Jews, the weaving is done by
the Tadjik and Mervi, who, in accordance with the taste and fashion
of the country, prepare only stuffs of glaring colours.
In former times, especially during the Arabian occupation, the silk
stuffs of Central Asia were celebrated throughout the East; but when
the cleverest of the artisans were transferred by the conquerors to
Damascus and Bagdad, the old art gradually disappeared, and is
now gone for ever, in spite of the efforts of Timur to transplant it
back from Transoxania. How great is the quantity of silk produced
here, is shown by the circumstance, that the greater part of the
cotton stuffs, called aladja, that are generally worn, are strongly
intermixed with silk; that not only the rich, but every man of middle
rank, possesses one or more garments, several table-cloths and
pocket-handkerchiefs made of silk; and that a considerable export
trade in silk is carried on, not only with Persia, India, and
Afghanistan, but to a large extent with Russia.
The cotton in Central Asia promises to become an important article
for the future. It is cultivated in large quantities in the three
Khanats, furnishing the material for the upper and under garments
of every body, high and low, for their bed-clothes, and cloths of
every kind. The cotton in Turkestan is better than the Indian,
Persian, and Egyptian, and is said to equal the far-famed American
cotton. At present, however, Russia alone consumes this article in
her manufactures at Moskau, Wladimir, Tverskoy, &c., and in
quantities which increase annually in a surprising degree. The
69. manufacturers complain greatly of the clumsy management of the
planters, especially of the insufficient cleansing of the cotton from
the seeds, as well as of the dishonesty of the traders, who wet the
bales, or fill them with stones, to make them heavier. Nevertheless,
the cotton, which is imported from Khiva and Bokhara by Orenburg,
is almost indispensable to Russian industry.
In Central Asia the cultivation of cotton is comparatively easy and
convenient, the cotton fields requiring no irrigation, and the rain
being considered, if anything, prejudicial even in the spring. A hard,
stony ground, called Soga, is always chosen, and is ploughed once;
on the whole, the cultivation of cotton is the least troublesome of all
field occupations. According to the statistical dates of the Orenburg
custom-house the greatest quantity of cotton is produced in the
Khanat of Bokhara; this statement, however, rests upon an error,
since the caravans of Khiva, when crossing the Jaxartes, frequently
join the Bokhariots, or they give themselves out for Bokhariots;
these latter standing on a much better footing with the Russians,
whilst the people of Khiva are in very ill favour with them. I know
from my own experience, and have convinced myself by frequent
inquiries, that not only is the cultivation of cotton far more
flourishing in Khiva, but its quality is far superior to that in the two
sister Khanats. The pod, here called gavadje, is smaller than that of
Bokhara; but the cotton is much finer and whiter even than the
guzei sefid, that is, the first quality of Bokhariot cotton industry. The
Central Asiatics themselves give the preference to the Khiva
production, a fact which tends to confirm our opinion. In dyeing and
weaving Bokhara stands pre-eminent, but the stuffs from Khiva are
better paid in her capital than her own manufactures. They are
exported to Afghanistan, India, and Northern Persia, and are a
highly-prized article even among the nomads.
There is no doubt that the cotton of the oasis countries will one day
considerably increase in value. Several circumstances of paramount
and urgent necessity must combine to further this object. Above all
things, it is requisite that important improvements should be
introduced in the mode of cultivation; our European machines should
70. come in aid of the cleansing and packing, and the roads should be
rendered, as far as possible, secure. By these means the cotton
would not only be improved in quality, but, without any great
additional expense, the quantity might be considerably multiplied. It
is very probable that Central Asia may one day, although not in the
immediate future, be to Russia what New Carolina is to the
manufacturing towns of England at the present day.
The immense increase in the exportation of cotton from Central Asia
is shown very clearly in the Blue Books of 1862 and 1865, in the list
which Mr. Saville Lumley, former secretary to the English embassy at
St. Petersburg, has contributed. According to this official statement
the Khanats exported to the value of—
71. Bokhara. Khiva. Khokand.
Roubles. Roubles.Roubles.
——— ——— ——— ———
1840-18502,065,697 470,781 16,851
——— ——— ——— ———
1853 280,514 133,799
1854 509,600 248,347 The
1855 513,023 185,683 dates
1856 501,225 36,050 are
1857 578,483 66,776wanting.
1858 634,643 59,729
1859 495,065 2,274
1860 721,899 22,429 4,907
——— ——— ——— ———
Total 4,234,412 755,087 4,907
From this list we see, that the exports of 1840-1850 did increase
more than double during the next ten years, and under favourable
political circumstances would, no doubt, continue to increase.
We must add the remark, that although Bokhara shows in this list
throughout the largest figures, it does not by any means follow that
they are the result of its own exclusive production. Much Khiva
cotton has been included, as well as the cotton which the Urgends
traders carry to Orenburg on the Bokhara road. The Orenburg
custom-house furnishes the list, and all the cotton is entered under
the head of Bokhara. In like manner much Khokand cotton is mixed
up with it. The Khokand traders give themselves out for Bokhariots
on the frontier, on account of the frequent hostilities between their
tribe and the Russians.
2. The Animal Kingdom.
We must mention first of all the domestic animals, and among these
the genus, sheep. Two species are usually distinguished: 1, the
72. Kazak koy (the Kirghis sheep); and, 2, the Œzbeg koy (the Œzbeg
sheep). The Kirghis sheep is preferred to the latter, for its wool as
well as its meat. Throughout Central Asia we meet with the fat-tailed
sheep. Of these it is said, that their masters are obliged to fasten
either cylinders or wheels under their broad, thick tails, which they
drag after them on the ground, in order to render walking easier to
them, or rather to enable them to walk at all—a story which is by no
means exaggerated, however incredible it may appear. The so-called
Bakkan koy, the fatted sheep, give often from two to three batman
of pure fat. The meat I found, in point of taste and flavour, superior
to any in all those parts of Asia I am acquainted with. The highly
celebrated Kivirdjik and Karaman sheep in Turkey cannot be
compared to them; and even the south Persian sheep, of which the
Persians are exceedingly proud, are inferior to them.
The wool is not of the same excellence, and is used less for clothing
(probably for want of knowledge in the preparation of it) than for
carpets, travelling-bags, horse-cloths, and similar other coarse
stuffs; it is little seen in the export trade. Black, curly lamb-skins, on
the other hand, form an important article of trade. Its chief source is
Bokhara, especially Karaköl; from here it is exported all over Asia,
and even to Europe, where it is known under the name of
Astrachan. The skin is drawn off the young lamb two or three days
after its birth, and then softened in barley meal and salt. It is said,
that washing it in the water of the Zerefshan gives it the beautiful
lustre; and in the month of July thousands of them may be seen
spread out for drying along its banks, between Bokhara and
Behaeddin. The skins are everywhere admired, but mostly in request
in Persia, where they are made into the fashionable hats of the
country. If we take into account, that a külah (a hat, for which three
or four skins are used) costs there as much as from ten to fifteen
ducats, we may feel assured that our Astrachan of a considerably
lower price is no Bokhara production. With the nomads of Central
Asia the breeding of sheep is a chief means of maintenance, and we
can easily form an idea of the innumerable flocks of sheep which
graze and rove upon the steppes. The Kirghis send great quantities
73. of sheep to the Khanats and to Russia, where the importation is
constantly on the increase. In the year 1835 about 850,000, and in
the year 1860 already 3,644,000 roubles' worth of sheep were
imported.[30]
In addition to this enormous quantity of sheep, raw
sheep-skins to the value of 75,000, and wool to the value of 86,000
silver roubles, passed the Russian frontier at Orenburg in the same
year.
The goat is, after the sheep, one of the most important of domestic
animals. Goats' flesh is not so palatable as that of sheep, but it is
here better than anywhere else in Asia. The wool of the goat,
according to Burnes, is far inferior to that of the Cashmir goat, but
tolerably good; and waterproof stuffs are made of it.
Horses, of excellent breed, are found among the Turkomans, who
export the finest to Afghanistan, India and Persia. The Turkoman
horse, especially the Akhal and Yomut race,[31]
is very little inferior to
the Arab horse in point of swiftness and endurance, as well as in
beauty of form. The Œzbeg horse, or the species met with in
Bokhara, Khiva, and Maymene, possesses more strength than
swiftness.
The camels of Central Asia, among which the breed of Bokhara and
the two-humped Kirghis are considered the best of their kind, are
surpassed in point of strength and swiftness only by the Arab, and
especially by the Hedshaz camel. The story that the camels can
preserve water pure and cool in their second stomach, and that
travellers, when suffering from thirst, drink it in their utmost need, is
perfectly unknown here; and on questioning the nomads on the
subject, they only laughed and seemed highly amused. These
animals are famous in Central Asia for their rare contentedness,
satisfied as they are with the very worst water, and most miserable
food, consisting of thistles and briars, and in spite of which they hold
on for days, loaded with the heaviest burdens. They are at the same
time entirely free from the spite and viciousness of the Arabian
camel. They are exported to Russia and Afghanistan; less to Russia.
Their hair is cut twice a year, and is used in the manufacture of
74. ropes and coarse stuffs. Cattle on the whole are not very numerous,
and in rather a poor condition. The finest cattle are said to exist in
Khokand, and among the Karakalpaks on the Oxus, whose exclusive
occupation is to rear them. Beef is, in Central Asia, still more tough
and unpalatable than in Persia or Turkey, and the consumption of it
is therefore limited to the poorest class of the people. Butter and
cheese are made of cow's milk, but in comparatively small
quantities. Mules are not found in Central Asia, from a religious
superstition against disgracing the horse, the noble animal, "par
excellence;" but all the greater care is bestowed upon the breeding
of the ass, which undoubtedly is here the finest and most excellent
of all I have seen in Asia. The ass is, in Bokhara, not only of a
vigorous frame and high stature, but of surprising nimbleness, and
in long caravan marches can be relied upon as much as the horse.
The fowls are of the long-legged Chinese breed. Geese are smaller
than those in Europe; and there are several species of ducks.
Besides these, there are swans, partridges, guinea-fowls and
pheasants, of which the finest sort is found in Khokand.
3. Mineral Kingdom.
My readers will not feel surprised that we should have but a scanty
knowledge of the mineral riches in the three Khanats. Lehmann, and
other Russian travellers, who, furnished with sufficient geological
knowledge, might have made closer investigations, were thwarted in
their efforts at every step by the jealousy of the Tartar officials. I
incline, however, to the opinion of Burnes, that Central Asia
possesses either no precious metals or extremely few, and that the
gold dust in the Zerefshan is not the property of the country, but
washed down by the small rivers that rise in the Hindukhush.
According to a statement of the Central Asiatics, the mountainous
country round Samarkand and in Bedakhshan, the Oveis-Karayne
mountains on the left bank of the Oxus (in the Khanat of Khiva), and
the Great Balkan in the desert near the Caspian Sea, are rich in
metallic wealth. That gold mines really do exist near the upper Oxus,
75. is proved by a certain considerable quantity of gold annually
obtained from it, although the gold-washing is carried on in the most
primitive and negligent manner.
The gold-washing, or more correctly the gold-fishing, is done with
camels' tails, of which several are hung up side by side between two
poles. People beat them about in the water for some time, or they
dip them into the river, and then hang them up. Those places are
always chosen where the water is troubled, and the work is
generally performed in June and July, the months in the year most
fit for the purpose. I doubt whether any gold-dust is exported; it is
not probable, since the smaller ornaments are made of native metal,
as the Persian goldsmith in Bokhara informed me. Silver is found in
Khiva in the above-mentioned mountains, and a considerable
quantity of this valuable metal was really gained during the reign of
Allahkuli-Khan, when the miners were worked for three years under
the management of a native of India, who had been educated for
this department. It is said that after the death of this prince he
either fled or was murdered. Since that time the mines have been
much neglected. I also heard some vague reports of the existence of
silver mines near Shehri Sebz.
Of precious stones, we must mention first of all the rubies of
Bedakhshan, which were formerly of high repute in Asia, under the
name of Laali Bedakhshan; at the present day not many of them are
found. Cornelian exists in large quantities in the mountain-rivers of
Bedakhshan. It is very cheap, and is exported to Arabia, Persia, and
Turkey. Lapis lazuli, which is used in dyeing, is of small value in
Central Asia, and is exported to Russia and Persia. The turquoise of
Bedakhshan and Khokand is far inferior in colour to that of Nishapur
in Persia, and is purchased by none but the nomads and Nogay
silversmiths; it is of a green instead of a blue colour, and liked far
less than the latter.[32]
This sketch of the productions of the oasis countries in Central Asia
will have convinced my readers, and especially those who are
acquainted with Asiatic countries and their conditions, that Turkestan
76. cannot be numbered among the sterile countries. Called by the
natives "a jewel set in sand," from its own peculiar value and the
barrenness around it, Central Asia will certainly play an important
part one day among the countries of the far East, and occupy a
prominent position, as soon as the beneficent beams of our
European civilisation shall have dried up the stagnant pool of its
miserable social relations, and as soon as the grand results we have
gained for industry and agriculture shall there likewise have received
their acknowledgment. It is robbery, murder, and war, but not the
barrenness of nature, which convert the shores of the Oxus and
Jaxartes into a desert. In Bokhara, but especially in Khiva,
agriculture is almost exclusively in the hands of slaves, of which
there are in the latter Khanat more than 80,000. Their rude manners
have placed the sword in the hands of the inhabitants,—the plough
is considered degrading, and is entirely given over to slaves. When
will these Khanats learn to see that a great part of their misfortunes,
and the unsettled state of their political and social relations,
originate in the perversity of their nature and conduct?
A government which endeavours to smooth existing relations
deserves our full acknowledgment and cordial wishes for success,
although it is premature to anticipate a complete change. Nor must
we grudge it the natural wealth of the country. Setting aside the
moral influence of such a Government, and its possible future
political schemes, the material gain is, on the whole, not large; nay,
I maintain, that it is small, when compared to the trouble and
expense the occupation and administration of such a province
require—a province, the communication with which must always be
attended with endless hardships and difficulties.
77. CHAPTER XV.
ON THE ANCIENT HISTORY OF BOKHARA.
What I have to impart in this chapter on the ancient history of
Bokhara is taken out of a Persian MS., brought by the late Sir
Alexander Burnes from Bokhara, which bears the name of "Tarikhi
Narshakhi," the history of Narshakhi. The author, Mehemmed ben
Djafer el Narshakhi, wrote this highly interesting work in Bokhara, in
the year of the Hegirah, 332, under the government of Emir Hamid
the Samanide, in Arabic. Later, in the year 522, it was translated into
Persian, and augmented by quotations from a not less interesting
work, Khazain ul Ulum, "The Treasures of Wisdom," which Ebul
Hassan wrote at Nishapur. In consideration of its historical value it is
well worth the trouble (in a quite literal translation) to give the
whole. The distinguished orientalist, Monsieur de Khanikoff, has
already done this, and it will very probably be put before the
scientific world. We have here only selected that which is suitable to
the outline of our sketches, and for this reason given an extract in a
free translation, since this is less fatiguing to the majority of readers,
and more acceptable.
Bokhara, i.e., its Environs.
On the site of modern Bokhara there must have been in ancient days
a morass, which arose from the yearly flooding of the river that
comes from Samarkand. In summer, from the melting of the snow in
the existing mountains in the neighbourhood, this was much
augmented. This morass was dried up at a later period, and the
fertile soil soon attracted settlers from all sides. From these colonists
a prince was chosen, by name Aberzi, for their ruler. Bokhara itself
78. existed not then. There were simply numerous villages, of which
Beykem or Beykend (the village of the ruler) was the largest.
Tyranny soon dispersed this little colony. A part of it drew back to
northern Turkestan, founded the town Djemuket,[33]
and soon
enjoyed a flourishing condition. Later they returned to the assistance
of their brethren whom they had left behind. Then Prince Shir
Kishver, "Lion of the Land," conquered the bad Aberzi, put him in a
sack full of thorns, and turned him round and round until he died.
Bokhara gradually flourished again. Shir Kishver ruled for twenty
years, and contributed much to the success of the colony, and his
followers pursued the same path, and the whole neighbourhood was
soon peopled and covered with villages. In what epoch the
chronology of this place falls, is hard to conjecture. It were a vain
effort to attempt to penetrate the table of the oldest history of
Bokhara. We prefer rather to give the interesting data of the MSS. on
that neighbourhood, and to begin with Bokhara, which from ancient
days was an important spot.
Bokhara, the Capital.
What the source of our information relates with regard to the
religious importance of this spot, what pre-eminence its inhabitants
had, what distinction awaits them at the day of resurrection, &c., will
not much interest our readers. Siaush is stated to have been the
founder of the fortress, where he was slain in a public square, before
the Gate Guriun, by his own father-in-law. This place was constantly
held in honour by the fire-worshippers, and every one took care to
offer a cock there on Noruz (New Year's Day) before the set of sun.
This commemorative festival was celebrated everywhere.
Troubadours have long sung of it in their lays, though the story
relates to facts that happened three thousand years ago. Other
people affirm that Efrasiab was the founder. It may suffice to know
that the fortress long remained desolate and uninhabited until
Benden, or Bendun, the husband of Queen Khatun, rebuilt it,
together with a castle over the gate, on which he caused his own
79. name to be engraved in iron. In the year 600 Heg. this gate,
together with the iron slab, was still conspicuous; later all fell in
ruins, and every attempt to rebuild it was fruitless. After the opinion
of the wise men of the day it was at length rebuilt in the form of the
Pleïades, on seven pillars, and from that time all kings who inhabited
it were victorious, and, what is still more wonderful, none of them
died, as long as they continued to occupy it. This castle had two
gates—the Eastern or Gurian Gate, the western or Rigistan Gate—
which were connected by a road, and the castle contained the
dwellings of the chief officers, as well as the prison and treasury and
divan. After these events there was a time of desolation, and it was
again rebuilt by Arslan Khan, and enjoyed its former greatness, 534
Heg. When Kharezm Shah took Bokhara he permitted governors
appointed from Sandjar to direct matters, and to destroy the citadel.
Then, in 536 Heg., it was again restored. Similar events it
experienced many times, till at last the Moguls, under Djengis Khan,
reduced to ruins Bokhara and the fortress.
Of the palaces of Bokhara, the Seraï at the Rigistan must be
mentioned in the first place, in which square the lords of this land,
both in the pre-Islamite times and also later, were in the habit of
living. In regard to circumference, that which Emir Said, the
Samanide, caused to be built is the largest, and probably most
splendid palace, where all the high counsellors, with the governors,
are found in one and the same building.
After this, we must name Seray Molian, or that palace which was
built on the canal of the same name. This is described as an
exceedingly charming dwelling-place, which was surrounded by the
most luxurious gardens, the most beautiful meadows and flower-
beds, brooks and fountains. The whole tract of country, from the
gate of the Rigistan to Deshtek (little field) was quite full of
beautifully-painted, sumptuous houses, with lovely lakes, and
shadowy trees which allowed no sun to penetrate; and the gardens
exuberant in fruits, as almonds, nuts, cherries, &c.[34]
80. The palace of Shemsabad is also worthy of notice, which the king,
Shems-ed-din, caused to be built near the gate Ibrahim, and which
is remarkable for its zoological garden, named Kuruk. This was a
place of four miles in circumference, surrounded with high walls,
where many dove-cotes, as well as wild animals, such as apes,
gazelles, foxes, wolves, boars(!), in half-tamed condition, are found.
After the death of Shems-ed-din, his brother, Khidr Khan, mounted
the throne; then his son, Ahmed Khan, who continually increased
the beauty of the palace; but when the latter was conquered and
conducted to Samarkand by Melek Shah, it was abandoned, and fell
into ruins. Besides these there were many country houses in the
neighbourhood, nearer to the town, which belonged to the
Keshkushans. By this name a certain people were indicated who
came out of the west to Bokhara, but were not Arabs, and
possessed a singularly good reputation. When Kuteibe, after the
conquest of Bokhara, required the half of the houses for the Arabs,
the Keshkushans formed the largest portion of those who gave up
their houses and settled out of the town. Of these country houses
only two or three remained to later periods, which bore the name of
Köshki Mogan (Kiosks of the fire-worshipping priests). There were
many temples in Bokhara known as those of the fire-worshippers,
and the Mogan were accustomed to maintain them with great care.
The first town wall which extended round Bokhara was built by the
command of the governor, Ebul Abbas, in 215 Heg., in consequence
of the inhabitants having complained that they had suffered so much
from the inroads of the Turks. In the year 235 Heg., it was repaired
and fortified, but later entirely ruined when the Mongol hordes laid
waste the city and environs of Bokhara. Besides the above, mosques
and other buildings are mentioned. We wish to spare our readers
these details. The past prosperity of Bokhara is sufficiently shown,
when we appeal to twelve canals or larger conduits which intersect
the vicinity in all directions. The fruitful and bounteous nature of the
soil has, in the East, become proverbial, and the great sums which
have been levied on the town and environs prove it. After the fourth,
i.e., the final conquest of Bokhara by Kuteibe, the Khalif in Bagdad
received 200,000, and the governor of Khorassan 10,000, dirrhems.
81. In the time of the Samanides Bokhara paid, in Kerminch alone, more
than a million dirrhems tribute, which is considered an immense sum
according to the tariff of that period. In pre-Islamite times there was
in Bokhara only barter. The first governor who struck silver money
was Kanankhor. The coin had on one side his portrait, and was of
pure silver: this lasted up to the time of Abubekir. The old coinage
became lessened, and was replaced by the inferior mint at Kharezm.
In the time of Harun al Raschid, Athref, the governor, struck a new
mint of six different kinds of metal, which were named atrifi or azrifi.
(I think that the word, common in Persia, eshrefi—ducats, is not
from the Arabic, but derived from azrifi.)
In industrial arts also, Bokhara has exceeded the other nations of
once famous Asia. The dress stuffs which were fabricated on the
bank of the Zerefshan were sought for in Arabia, Persia, Egypt,
Turkey, India itself. These were merely of three colours, white, red
and green; but its silken stuffs were strong and heavy, and were
worn for a long time as the favourite royal and princely robes in
many lands. Next to these were the large carpets and curtains,
which were woven in Bokhara. The former of these were so
expensive that the town of Bokhara could pay, with one single
carpet, the tribute to Bagdad. In the later devastations of Bokhara
the clever artizans were scattered, and with them their art fell to the
ground.
The Environs of Bokhara.
Besides the chief city and its wonders, there are many places of the
environs described in the manuscript before me. Some of these exist
even now; others have passed nameless.
Kermineh. In this many other towns are comprised, and this region
has produced many poets and poetesses. It is distant from Bokhara
fourteen farsangs only, and was named Dihi Khurdek (little town).
Nur is a larger place, where there are many mosques and
caravanserais, and it is the spot most frequented by pilgrims of the
82. whole neighbourhood. In Bokhara much is thought of this, for a
journey thither is esteemed as half a pilgrimage to Mecca.
Tavais (as the Arabians name it, for the proper name was Kud), a
considerable spot, which was celebrated for its markets. They lasted
commonly ten days, and were frequented yearly by more than ten
thousand persons, who came from Ferghana (Khokand) and from all
quarters. This circumstance made the inhabitants wealthy, and they
were famous for their riches. Tavais lies on the high road to
Samarkand, and is seven farsangs from Bokhara.
Ishkuhket, a large and rich town, carries on an extensive commerce
in preparing kirbas (a kind of linen); has many mosques,
caravanserais, and is considered one of the loveliest towns of
Bokhara.
Zendine produces the best kirbas in Bokhara, which it exports to
Arabia, Fars, Kirman, and other distant lands, and which is used
everywhere by princes and great people for clothing. It is in high
estimation, and is purchased at the same price as the heaviest
stuffs.
Revane is a fortified spot, and was formerly the residence of the
kings, and it is said that it was built by Shapur. It is on the Turkestan
boundary, has a weekly market, at which much silken stuff is sold.
Efshana is a well fortified spot, has a mosque built by Kuteibe, and a
weekly market.
Berkend, a large old village, which the Emir Ismael, the Samanide,
bought, and divided the revenue between Dervishes and Seids.
Rametin is older than Bokhara, and was earlier inhabited by princes.
It is said to have been built by Efrasiab, who fortified it also at a
later period, when he was attacked by Kaykhosrev, who sought
vengeance on him for the death of his father, Siaush, and son-in-law.
In this place were the most celebrated temples of the fire-
worshippers in all Transamana. Efrasiab was, after two years, seized
and killed by Kaykhosrev, and his grave is found at the entry of that
fire-temple, which stands on that high hill which is now visible close
83. to the mountains of Khodscha Imam. These events are reported to
have taken place three hundred years ago.
Yerakh'sha is one of the Bokhara towns, and is celebrated for its
castle, which was built by Prince Gedek, one thousand years since,
and then lay long years in ruin. Later, Prince Hebek restored a
portion, and Benyat, the son of Tugshade, is said to have died there.
In the time of Islam, Emir Ismael, the Samanide, wished to make a
mosque of it, and offered the inhabitants 20,000 dirrhem as a re-
imbursement for the restoration, but they declined his offer. In the
time of Emir Hayder, the Samanide, there were yet some wooden
remains, which that person brought to Bokhara, and used for the
building of his castle. Yerakh'sha has yearly fifteen markets, of which
the last, which is held at the end of the year lasts twenty days, and
also is called the Noruz market (New Year's Day market), which
since that time (what time?) has become a Bokhara custom. Five
days after the Noruz market comes the Noruz Mogan (New Year's
Day of the priests of the fire-worshippers).
Beykend was considered a city, and its inhabitants are highly
indignant if any one call it a village. Were a Beykender in Bagdad
questioned as to his home, he would say Bokhara. It was once a
considerable spot, had many beautiful buildings and mosques, and in
the year 240 Heg. had yet many rabats (stone houses in the form of
a caraverserai). The number of these exceeded a thousand, all
inhabited by people who, in summer, dwelt at their own country
seats, but in winter spent the fruits of their industry in the town, and
thus were very gay. The Beykenders were also great merchants, who
carried on a trade to China and the Sea. The fortifications of this
town are older than Bokhara, and it gave Kuteibe much trouble to
take it. In earlier times each prince had here his castle. Between
Beykend and Farab is a tract of twelve farsangs, which goes through
a sandy desert. Arslan Khan had raised here a magnificent building,
and with much cost brought the Canal Djaramgam into this vicinity.
In the neighbourhood of Beykend there are many beds of reeds and
large lakes, which they call Barkent ferrakh or Karakol. According to
a credible statement these are about twenty farsangs in extent, and
84. abound in water-fowl and fish, beyond any other portion of
Khorassan. Here the Canal Djaramgam had not sufficient water, so
Arslan Khan wished to bring from these lakes a stream to Beykend,
which place lies on a slight elevation. They began to dig, but they
struck on an excessively hard rock, which rendered useless all their
hammering and hewing. Loads of fat and vinegar were employed for
the softening of the stone, but in vain, and the work was
abandoned.
Farab has a large mosque, of which the walls and cupola are built of
tiles, without a particle of wood visible. It had its own princes, who
governed from Bokhara in a settled order, and, to a certain degree,
independently.
Queen Khatun and the Four First Arabian Field
Marshals.[35]
In the time of the Arabian occupation, or more properly speaking, in
that time when the first outposts of the Arabian adventurer pressed
to the distant East, there was in Bokhara a woman on the throne,
who, during the minority of her son Tugshade, held for fifteen years
the reins of government with both might and rectitude. Of this
woman, who is considered to be the Nushirvan (emblem of justice)
of Central Asia, it is reported that she went daily from her castle on
the Rigistan[36]
on horseback, and, surrounded by all classes, busied
herself with state affairs. Towards the end of year 53 Heg., the
Arabians, under the leading of Abdullah-ben-Ziad, crossed the Oxus,
and took the once celebrated Peykend, through which victory they
came into possession of much treasure, and about 4,000 prisoners.
In the year 54, Heg., they attacked Bokhara with a strong army and
battering engines, and Khatun was cowed before the threatening
peril. One messenger was sent by her to the Arabian field-marshal
with presents, and instructions to obtain at least an armistice for
fourteen days; another was sent to the north-east to a Turkish race,
for quick aid. The stratagem was successful. The Arabs, anticipating
85. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com