cshtp5_01

116
©1992-2014 by Pearson Education, Inc. All Rights Reserved.

description

Apresentação de C#

Transcript of cshtp5_01

Page 1: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 2: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 3: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 4: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 5: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 6: cshtp5_01

Computers process data under the control of sequences of instructions called computer programs.

These programs guide computers through actions specified by people called computer programmers.

The programs that run on a computer are referred to as software.

You’ll learn object-oriented programming—today’s key programming methodology that’s enhancing programmer productivity, and reducing software development costs.

You’ll create many software objects that model both abstract and real-world things.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 7: cshtp5_01

A computer consists of various devices referred to as hardware, such as the keyboard, screen, mouse, hard disks, memory, DVD drives, printer and processing units).

Every year or two, the capacities of computer hardware have approximately doubled inexpensively.

This remarkable trend often is called Moore’s Law, named for the person who identified it, Gordon Moore, co-founder of Intel—the leading manufacturer of the processors in today’s computers and embedded systems, such as smartphones, appliances, game controllers, cable set-top boxes and automobiles.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 8: cshtp5_01

Moore’s Law and related observations apply especially to ◦ the amount of memory that computers have for running programs

and processing data◦ the amount of secondary storage (such as hard disk storage) they

have to hold programs and data over longer periods of time ◦ their processor speeds—the speeds at which computers execute their

programs (i.e., do their work). Similar growth has occurred in the communications field, in

which costs have plummeted as enormous demand for communications bandwidth (i.e., information-carrying capacity) has attracted intense competition.

Such phenomenal improvement is truly fostering the Information Revolution and creating significant career opportunities.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 9: cshtp5_01

Data items processed by computers form a data hierarchy that becomes larger and more complex in structure as we progress from the simplest data items (called “bits”) to richer data items, such as characters, fields, and so on.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 10: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 11: cshtp5_01

BitsThe smallest data item in a computer can assume the value 0 or the value 1. Such a data item is called a bit (short for “binary digit”—a digit that can assume either of two values). It’s remarkable that the impressive functions performed by computers involve only the simplest manipulations of 0s and 1s—examining a bit’s value, setting a bit’s value and reversing a bit’s value (from 1 to 0 or from 0 to 1).

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 12: cshtp5_01

Characters We prefer to work with decimal digits (0–9), uppercase letters (A–Z), lowercase letters (a–z), and special symbols (e.g., $, @, %, &, *, (, ), –, +, ", :, ? and / ). Digits, letters and special symbols are known as characters. The computer’s character set is the set of all the characters used to write programs and represent data items on that device. Computers process only 1s and 0s, so every character is represented as a pattern of 1s and 0s. The Unicode character set contains characters for many of the world’s languages.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 13: cshtp5_01

C# supports several character sets, including 16-bit Unicode® characters that are composed of two bytes—each byte is composed of eight bits.

See Appendix B for more information on the ASCII (American Standard Code for Information Interchange) character set—the popular subset of Unicode that represents uppercase and lowercase letters in the English alphabet, digits and some common special characters.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 14: cshtp5_01

FieldsJust as characters are composed of bits, fields are composed of characters or bytes. A field is a group of characters or bytes that conveys meaning. For example, a field consisting of uppercase and lowercase letters could be used to represent a person’s name, and a field consisting of decimal digits could represent a person’s age.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 15: cshtp5_01

Records Several related fields can be used to compose a record. In a payroll system, for example, the record for an employee might consist of the following fields (possible types for these fields are shown in parentheses):

◦ Employee identification number (a whole number)◦ Name (a string of characters)◦ Address (a string of characters)◦ Hourly pay rate (a number with a decimal point)◦ Year-to-date earnings (a number with a decimal point)◦ Amount of taxes withheld (a number with a decimal point)

Thus, a record is a group of related fields. In the preceding example, all the fields belong to the same employee.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 16: cshtp5_01

FilesA file is a group of related records. More generally, a file contains arbitrary data in arbitrary formats. In some operating systems, a file is viewed simply as a sequence of bytes—any organization of the bytes in a file, such as organizing the data into records, is a view created by the programmer.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 17: cshtp5_01

DatabaseA database is a collection of data that’s organized for easy access and manipulation. The most popular database model is the relational database in which data is stored in simple tables. A table includes records composed of fields.

◦ For example, a table of students might include first name, last name, major, year, student ID number and grade point average fields.

◦ The data for each student is a record, and the individual pieces of information in each record are the fields.

You can search, sort and otherwise manipulate the data based on its relationship to multiple tables or databases.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 18: cshtp5_01

Big DataThe amount of data being produced worldwide is enormous and growing explosively. According to IBM, approximately 2.5 quintillion bytes (2.5 exabytes) of data are created daily and 90% of the world’s data was created in just the past two years! (www-01.ibm.com/software/data/bigdata/)

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 19: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 20: cshtp5_01

Computers can be envisioned as divided into various logical units or sections:

Input Unit◦ This “receiving” section obtains information (data and computer programs)

from input devices and places it at the disposal of the other units for processing.

◦ Most information is entered into computers through keyboards, touch screens and mouse devices.

◦ Other forms of input include receiving voice commands, scanning images and barcodes, reading from secondary storage devices (such as hard drives, CD drives, DVD drives, Blu-Ray Disc™ drives and USB flash drives), receiving video from a webcam or smartphone and having your computer receive information from the Internet (such as when you download videos from YouTube™ or e-books from Amazon).

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 21: cshtp5_01

Output Unit This “shipping” section takes information that the computer

has processed and places it on various output devices to make it available for use outside the computer.

Most information that’s output from computers today is displayed on screens; printed on paper; played as audio or video on PCs and media players and giant screens in sports stadiums; transmitted over the Internet or used to control other devices.

Computers also can output their information to networks, such as the Internet.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 22: cshtp5_01

Memory Unit This rapid-access, relatively low-capacity “warehouse”

section retains information that’s entered through the input unit, making it immediately available for processing when needed.

The memory unit also retains processed information until it can be placed on output devices by the output unit. Information in the memory unit is volatile—it’s typically lost when the computer’s power is turned off.

The memory unit is often called either memory or primary memory.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 23: cshtp5_01

Arithmetic and Logic Unit (ALU) This “manufacturing” section performs calculations,

such as addition, subtraction, multiplication and division.

It also contains the decision mechanisms that allow the computer, for example, to compare two items from the memory unit to determine whether they’re equal.

In today’s systems, the ALU is usually implemented as part of the next logical unit, the CPU.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 24: cshtp5_01

Central Processing Unit (CPU) This “administrative” section coordinates and

supervises the operation of the other sections. The CPU tells the input unit when information should

be read into the memory unit, tells the ALU when information from the memory unit should be used in calculations and tells the output unit when to send information from the memory unit to certain output devices.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 25: cshtp5_01

Many of today’s computers have multiple CPUs and, hence, can perform many operations simultaneously.

A multi-core processor implements multiple processors on a single “microchip”—a dual-core processor has two CPUs and a quad-core processor has four CPUs.

Many of today’s desktop computers have quad-core processors that can execute billions of instructions per second.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 26: cshtp5_01

Secondary Storage Unit This is the long-term, high-capacity “warehousing” section. Programs or data not actively being used by the other units

normally are placed on secondary storage devices (such as your hard drive) until they’re again needed, possibly hours, days, months or even years later.

Information on secondary storage devices is persistent—it’s preserved even when the computer’s power is turned off.

Secondary storage data takes much longer to access than information in primary memory, but the cost per unit of secondary storage is much less than that of primary memory.

Examples of secondary storage devices include CD drives, DVD drives and flash drives, some of which can up to 2 TB (TB stands for terabytes; a terabyte is approximately one trillion bytes).

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 27: cshtp5_01

Programmers write instructions in various programming languages (such as C#), some directly understandable by computers and others requiring intermediate translation steps.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 28: cshtp5_01

Machine Languages◦ Any computer can directly understand only its own machine

language, defined by its hardware architecture.◦ Machine languages generally consist of numbers, ultimately

reduced to 1s and 0s.◦ The term “code” has become more broadly used and now

refers to the program instructions in all levels of programming languages.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 29: cshtp5_01

Assembly Languages and Assemblers Machine language was simply too slow and tedious for

programmers to work with. Instead, programmers began using English-like

abbreviations to represent elementary operations. These abbreviations formed the basis of assembly

languages. Translator programs called assemblers convert

assembly-language programs to machine language quickly.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 30: cshtp5_01

High-Level Languages, Compilers and Interpreters

To speed up the programming process, high-level languages were developed in which single statements could be written to accomplish substantial tasks.

High-level languages, such as C#, Visual Basic, C++, C, Objective-C and Java, allow you to write instructions that look almost like everyday English and contain commonly used mathematical expressions.

Translator programs called compilers convert high-level-language code into machine language code.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 31: cshtp5_01

Objects, or more precisely the classes objects come from, are essentially reusable software components. ◦ There are date objects, time objects, audio objects, video objects,

automobile objects, people objects, etc. ◦ Almost any noun can be reasonably represented as a software object

in terms of attributes (e.g., name, color and size) and behaviors (e.g., calculating, moving and communicating).

Using a modular, object-oriented design-and-implementation approach can make software-development groups much more productive than was possible with earlier techniques—object-oriented programs are often easier to understand, correct and modify.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 32: cshtp5_01

The Automobile as an ObjectLet’s begin with a simple analogy. Suppose you want to drive a car and make it go faster by pressing its accelerator pedal. Before you can drive a car, someone has to design it. A car typically begins as engineering drawings, similar to the blueprints that describe the design of a house. Drawings include the design for an accelerator pedal. Pedal hides from the driver the complex mechanisms that actually make the car go faster, just as the brake pedal hides the mechanisms that slow the car, and the steering wheel hides the mechanisms that turn the car.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 33: cshtp5_01

Enables people with little or no knowledge of how engines, braking and steering mechanisms work to drive a car easily.

Before you can drive a car, it must be built from the engineering drawings that describe it.

A completed car has an actual accelerator pedal to make the car go faster, but even that’s not enough—the car won’t accelerate on its own (we hope), so the driver must press the pedal to accelerate the car.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 34: cshtp5_01

Methods and ClassesPerforming a task in a program requires a method.Houses the program statements that actually perform its task. Hides these statements from its user, just as the accelerator pedal of a car hides from the driver the mechanisms of making the car go faster.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 35: cshtp5_01

In object-oriented programming languages, we create a program unit called a class to house the set of methods that perform the class’s tasks.

A class is similar in concept to a car’s engineering drawings, which house the design of an accelerator pedal, steering wheel, and so on.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 36: cshtp5_01

Making Objects from ClassesJust as someone has to build a car from its engineering drawings before you can actually drive a car, you must build an object from a class before a program can perform the tasks that the class’s methods define. The process of doing this is called instantiation.An object is then referred to as an instance of its class.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 37: cshtp5_01

ReuseJust as a car’s engineering drawings can be reused many times to build many cars, you can reuse a class many times to build many objects. Reuse of existing classes when building new classes and programs saves time and effort.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 38: cshtp5_01

Reuse also helps you build more reliable and effective systems, because existing classes and components often have gone through extensive testing, debugging and performance tuning.

Just as the notion of interchangeable parts was crucial to the Industrial Revolution, reusable classes are crucial to the software revolution that has been spurred by object technology.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 39: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 40: cshtp5_01

Messages and Method CallsWhen you drive a car, pressing its gas pedal sends a message to the car to perform a task—that is, to go faster. Similarly, you send messages to an object. Each message is implemented as a method call that tells a method of the object to perform its task.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 41: cshtp5_01

Attributes and Instance VariablesA car has attributes

◦ Its color, its number of doors, the amount of gas in its tank, its current speed and its record of total miles driven (i.e., its odometer reading).

The car’s attributes are represented as part of its design in its engineering diagrams. Every car maintains its own attributes. Each car knows how much gas is in its own gas tank, but not how much is in the tanks of other cars.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 42: cshtp5_01

An object has attributes that it carries along as it’s used in a program.

Specified as part of the object’s class. A bank account object has a balance attribute that

represents the amount of money in the account. Each bank account object knows the balance in the

account it represents, but not the balances of the other accounts in the bank.

Attributes are specified by the class’s instance variables.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 43: cshtp5_01

EncapsulationClasses encapsulate (i.e., wrap) attributes and methods into objects—an object’s attributes and operations are intimately related. Objects may communicate with one another, but they’re normally not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves. Information hiding is crucial to good software engineering.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 44: cshtp5_01

InheritanceA new class of objects can be created quickly and conveniently by inheritance—the new class absorbs the characteristics of an existing class, possibly customizing them and adding unique characteristics of its own. In our car analogy, an object of class “convertible” certainly is an object of the more general class “automobile,” but more specifically, the roof can be raised or lowered.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 45: cshtp5_01

Object-Oriented Analysis and Design (OOAD)To create the best solutions, you should follow a detailed analysis process for determining your project’s requirements (i.e., defining what the system is supposed to do)Develop a design that satisfies them (i.e., deciding how the system should do it). Carefully review the design (and have your design reviewed by other software professionals) before writing any code.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 46: cshtp5_01

If this process involves analyzing and designing your system from an object-oriented point of view, it’s called an object-oriented analysis and design (OOAD) process.

Languages like C# are object oriented. Object-oriented programming (OOP) allows you to

implement an object-oriented design as a working system.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 47: cshtp5_01

The UML (Unified Modeling Language)The Unified Modeling Language (UML) is now the most widely used graphical scheme for modeling object-oriented systems.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 48: cshtp5_01

In the late 1960s, ARPA—the Advanced Research Projects Agency of the Department of Defense—rolled out plans to network the main computer systems of approximately a dozen ARPA-funded universities and research institutions.

ARPA implemented what quickly became known as the ARPAnet, the precursor of today’s Internet.

Its main benefit proved to be the capability for quick and easy communication via e-mail.

This is true even on today’s Internet, with e-mail, instant messaging, file transfer and social media such as Facebook and Twitter, enabling billions of people worldwide to communicate quickly and easily.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 49: cshtp5_01

The protocol (set of rules) for communicating over the ARPAnet became known as the Transmission Control Protocol (TCP).

TCP ensured that messages, consisting of sequentially numbered pieces called packets, were properly routed from sender to receiver, arrived intact and were assembled in the correct order.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 50: cshtp5_01

The Internet: A Network of NetworksIn parallel with the early evolution of the Internet, organizations worldwide were implementing their own networks for both intraorganization (that is, within an organization) and interorganization (that is, between organizations) communication. One challenge was to enable these different networks to communicate with each other. The Internet Protocol (IP) created a true “network of networks,” the current architecture of the Internet. The combined set of protocols is now called TCP/IP.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 51: cshtp5_01

Businesses rapidly realized that by using the Internet, they could improve their operations and offer new and better services to their clients.

This generated fierce competition among communications carriers and hardware and software suppliers to meet the increased infrastructure demand.

As a result, bandwidth—the information-carrying capacity of communications lines—on the Internet has increased tremendously, while hardware costs have plummeted.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 52: cshtp5_01

The World Wide Web (simply called “the web”) is a collection of hardware and software associated with the Internet that allows computer users to locate and view multimedia-based documents (documents with various combinations of text, graphics, animations, audios and videos) on almost any subject.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 53: cshtp5_01

In 1989, Tim Berners-Lee of CERN (the European Organization for Nuclear Research) began to develop a technology for sharing information via “hyperlinked” text documents.

Berners-Lee called his invention the HyperText Markup Language (HTML).

He also wrote communication protocols such as HyperText Transfer Protocol (HTTP) to form the backbone of his new hypertext information system, which he referred to as the World Wide Web.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 54: cshtp5_01

In 1994, Berners-Lee founded the World Wide Web Consortium (W3C), devoted to developing web technologies.

One of the W3C’s goals is to make the web accessible to everyone regardless of disabilities, language or culture.

You’ll use C# and other Microsoft technologies to build web-based apps.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 55: cshtp5_01

In 2000, Microsoft announced the C# programming language.

C# has roots in C, C++ and Java. C# has similar capabilities to Java and is appropriate for the

most demanding app-development tasks, especially for building today’s large-scale enterprise apps, and web-based, mobile and “cloud”-based apps.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 56: cshtp5_01

C# is object oriented. C# has access to the powerful .NET Framework Class

Library—a vast collection of prebuilt classes that enable you to develop apps quickly.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 57: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 58: cshtp5_01

C# is event driven. You’ll write programs that respond to user-initiated

events such as mouse clicks, keystrokes, timer expirations and—new in Visual C# 2012—touches and finger swipes—gestures that are widely used on smartphones and tablets.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 59: cshtp5_01

Microsoft’s Visual C# is a visual programming language—in addition to writing program statements to build portions of your apps, you’ll also use Visual Studio’s graphical user interface to conveniently drag and drop predefined objects like buttons and textboxes into place on your screen, and label and resize them.

Visual Studio will write much of the GUI code for you.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 60: cshtp5_01

C# has been standardized internationally. This enables other implementations of the language

besides Microsoft’s Visual C#, such as Mono (www.mono-project.com) that runs on Linux systems, iOS (for Apple’s iPhone, iPad and iPod touch), Google’s Android and Windows.

You can find the C# standard document at:

www.ecma-international.org/publications/standards/Ecma-334.htm

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 61: cshtp5_01

Today’s apps can be written with the aim of communicating among the world’s computers.

As you’ll see, this is the focus of Microsoft’s .NET strategy.

In Chapters 23, 29 and 30, you’ll build web-based apps with C# and Microsoft’s ASP.NET technology.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 62: cshtp5_01

In most programming today, each task in a program must finish executing before the next task can begin.

This is called synchronous programming and is the style we use for most of this book.

C# also allows asynchronous programming in which multiple tasks can be performed at the same time.

Asynchronous programming can help you make your apps more responsive to user interactions, such as mouse clicks and keystrokes, among many other uses.

Visual C# 2012’s new async and await capabilities simplify asynchronous programming, because the compiler hides much of the associated complexity from the developer.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 63: cshtp5_01

Figure 1.4 summarizes some popular programming languages with features comparable to those of C#.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 64: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 65: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 66: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 67: cshtp5_01

In 2000, Microsoft announced its .NET initiative, a broad vision for using the Internet and the web in the development, engineering, distribution and use of software.

.NET permits developers to create apps in any .NET-compatible language (such as C#, Visual Basic and many others).

Part of the initiative includes Microsoft’s ASP.NET technology, which is used to create web apps that users interact with via their web browsers.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 68: cshtp5_01

The .NET Framework contains the .NET Framework Class Library, which provides many capabilities that you’ll use to build substantial C# apps quickly and easily.

The .NET Framework Class Library has thousands of valuable prebuilt classes that have been tested and tuned to maximize performance.

You’ll learn how to create your own classes, but you should re-use the .NET Framework classes when possible to speed up the software development process, while enhancing the quality and performance of the software you develop.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 69: cshtp5_01

The Common Language Runtime (CLR) executes .NET programs and provides functionality to make them easier to develop and debug.

The CLR is a virtual machine (VM)—software that manages the execution of programs and hides from them the underlying operating system and hardware.

The source code for programs that are executed and managed by the CLR is called managed code.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 70: cshtp5_01

The CLR provides various services to managed code, such as integrating software components written in different .NET languages, error handling between such components, enhanced security, automatic memory management and more.

Unmanaged-code programs do not have access to the CLR’s services, which makes unmanaged code more difficult to write. (msdn.microsoft.com/en-us/library/8bs2ecf4.aspx)

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 71: cshtp5_01

Managed code is compiled into machine-specific instructions in the following steps: ◦ First, the code is compiled into Microsoft Intermediate Language

(MSIL). Code converted into MSIL from other languages and sources can be woven together by the CLR—this allows programmers to work in their preferred .NET programming language. The MSIL for an app’s components is placed into the app’s executable file—the file that causes the computer to perform the app’s tasks.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 72: cshtp5_01

◦ When the app executes, another compiler (known as the just-in-time compiler or JIT compiler) in the CLR translates the MSIL in the executable file into machine-language code (for a particular platform).

◦ The machine-language code executes on that platform.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 73: cshtp5_01

If the .NET Framework exists and is installed for a platform, that platform can run any .NET program.

The ability of a program to run without modification across multiple platforms is known as platform independence.

Code written once can be used on another type of computer without modification, saving time and money.

Previously, companies had to decide whether converting their programs to different platforms—a process called porting—was worth the cost.

With .NET, porting programs is no longer an issue, at least once .NET itself has been made available on the platforms.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 74: cshtp5_01

The .NET Framework provides a high level of language interoperability.

Because software components written in different .NET languages (such as C# and Visual Basic) are all compiled into MSIL, the components can be combined to create a single unified program.

Thus, MSIL allows the .NET Framework to be language independent. .NET 4.5 features .NET for Windows Store Apps—a subset of .NET

that’s used to create Windows 8 UI (user interface) style apps.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 75: cshtp5_01

Windows is the most widely used desktop operating system worldwide.

Operating systems are software systems that make using computers more convenient for users, app developers and system administrators.

They provide services that allow each app to execute safely, efficiently and concurrently (i.e., in parallel) with other apps.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 76: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 77: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 78: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 79: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 80: cshtp5_01

Windows StoreYou can sell Windows 8 UI desktop and tablet apps or offer them for free in the Windows Store. The fee is waived for Microsoft DreamSpark program students (see the Preface). To learn more about the Windows Store and monetizing your apps, visit msdn.microsoft.com/en-us/library/windows/apps/br229519.aspx.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 81: cshtp5_01

Windows Phone 8 is a pared down version of Windows 8 designed for smartphones.

Windows Phone 8 has the same core operating systems services as Windows 8, including a common file system, security, networking, media and Internet Explorer 10 (IE10) web browser technology.

However, Windows Phone 8 has only the features necessary for smartphones, allowing them to run efficiently, minimizing the burden on the device’s resources.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 82: cshtp5_01

You can sell your own Windows Phone apps in the Windows Phone Marketplace (www.windowsphone.com/marketplace).

You can also earn money by making your apps free for download and selling virtual goods (e.g., additional content, game levels, e-gifts and add-on features) using in-app purchase.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 83: cshtp5_01

Paid Windows Phone 8 apps range in price from $1.49 (which is higher than the $0.99 starting price for apps in Google Play and Apple’s App Store) to $999.99.

The average price for mobile apps is approximately $1.50 to $3, depending on the platform.

For Windows Phone apps, Microsoft retains 30% of the purchase price and distributes 70% to you.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 84: cshtp5_01

You can test your phone apps on the Windows Phone Emulator that Microsoft provides with the Windows Phone 8 SDK (software development kit).

To test your apps on a Windows phone and to sell your apps or distribute your free apps through the Windows Phone Marketplace, you'll need to join the Windows Phone Dev Center.

The program is free to DreamSpark students. The website includes development tools, sample code, tips

for selling your apps, design guidelines and more. To join the Windows Phone Dev Center and submit apps,

visit dev.windowsphone.com/en-us/downloadsdk.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 85: cshtp5_01

Cloud computing allows you to use software and data stored in the cloud—i.e., accessed on remote computers (or servers) via the Internet and available on demand—rather than having it stored on your desktop, notebook computer or mobile device.

Gives you the flexibility to increase or decrease computing resources to meet your resource needs at any given time.

More cost effective than purchasing expensive hardware to ensure that you have enough storage and processing power at their occasional peak levels.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 86: cshtp5_01

Also saves money by shifting the burden of managing these apps to the service provider.

With Windows Azure, your apps can store their data in the cloud so that the data is available at all times from any of your desktop computer and mobile devices.

Verified DreamSpark students can download Visual Studio 2012 Professional which includes built-in support for Windows 8 and Windows Azure.

You can sign up for a free 90-day trial of Windows Azure at www.windowsazure.com/en-us/pricing/free-trial/.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 87: cshtp5_01

C# programs are created using Microsoft’s Visual Studio—a collection of software tools called an Integrated Development Environment (IDE).

The Visual Studio 2012 IDE enables you to write, run, test and debug C# programs quickly and conveniently.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 88: cshtp5_01

[Note: This test-drive can be performed on a computer running either Windows 7 or Windows 8. The steps shown here are for Windows 7. Running an app on Windows 8 is discussed in Section 1.15.] You’ll now use Visual Studio Express 2012 for Windows Desktop to “test-drive” an existing app that enables you to draw on the screen using the mouse. The Painter app allows you to choose among several brush sizes and colors. The following steps walk you through test-driving the app.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 89: cshtp5_01

Step 1: Checking Your Setup Confirm that you’ve set up your computer and the software properly by reading the book’s Before You Begin section that follows the Preface.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 90: cshtp5_01

Step 2: Locating the Painter App’s Directory Open a Windows Explorer window and navigate to C:\examples\ch01\win7testdrive. (We assume you placed the examples in the C:\examples folder.) Double click the Painter folder to view its contents (Fig. 1.6), then double click the Painter.sln file to open the app’s solution in Visual Studio.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 91: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 92: cshtp5_01

Depending on your system configuration, Windows Explorer might not display file name extensions. To display them (like .sln in Fig. 1.6):

In Windows Explorer, type Alt + t to display the Tools menu, then select Folder options….

Select the View tab in the Folder Options dialog. Locate the checkbox Hide extensions for known file types

and ensure that it’s unchecked. Click OK to dismiss the Folder Options dialog.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 93: cshtp5_01

Step 3: Running the Painter AppTo see the running Painter app, click the Start button (Fig. 1.7) or press the F5 key. Figure 1.8 shows the executing app. The brush’s properties, selected in the RadioButtons labeled Black and Medium, are default settings—the initial settings you see when you first run the app. Programmers include default settings to provide reasonable choices that the app will use if the user does not change the settings. Default settings also provide visual cues for users to choose their own settings. Now you’ll choose your own settings as a user of this app.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 94: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 95: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 96: cshtp5_01

Step 4: Changing the Brush ColorClick the RadioButton labeled Red to change the brush color, then click the RadioButton labeled Small to change the brush size. Position the mouse over the white Panel, then drag the mouse to draw with the brush. Draw flower petals, as shown in Fig. 1.9.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 97: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 98: cshtp5_01

Step 5: Changing the Brush Color and SizeClick the Green RadioButton to change the brush color. Then, click the Large RadioButton to change the brush size. Draw grass and a flower stem, as shown in Fig. 1.10.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 99: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 100: cshtp5_01

Step 6: Finishing the DrawingClick the Blue and Medium RadioButtons. Draw raindrops, as shown in Fig. 1.11, to complete the drawing.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 101: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 102: cshtp5_01

Step 7: Stopping the AppWhen you run an app from Visual Studio, you can terminate it by clicking the stop button on the Visual Studio toolbar or by clicking the close box on the running app’s window.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 103: cshtp5_01

[Note: This test-drive can be performed only on a computer running Windows 8.]

Step 1: Checking Your Setup Confirm that you’ve set up your computer and the software

properly by reading the book’s Before You Begin section that follows the Preface.

Step 2: Switching to the Windows 8 Desktop Click the Desktop tile in the Windows 8 Start screen to

switch to the desktop.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 104: cshtp5_01

Step 3: Locating the Painter App’s Directory Click the File Explorer icon in the task bar to open a File Explorer window, then locate the C:\examples\ch01\win8testdrive folder. (We assume you placed the examples in the C:\examples folder.) Double click the Painter folder to view its contents (Fig. 1.12), then double click the Painter.sln file to open the app’s solution in Visual Studio.

◦ [Note: Depending on your system configuration, the File Explorer window might not display file name extensions. To display file name extensions (like .sln in Fig. 1.12), click the View tab in the File Explorer window, then ensure that File name extensions is selected.]

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 105: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 106: cshtp5_01

Step 4: Running the Painter AppWindows 8 UI apps normally occupy the full screen, though you can also snap apps to a 320-pixel-wide area at the left or right of the screen to see two apps side-by-side. To see the running Painter app, you can install it on the Windows 8 Start screen and execute it by selecting Local Machine (Fig. 1.13) then clicking the Start Debugging button or pressing the F5 key. Once you install the app on the Start screen, you can also run it by clicking its Start screen tile. Figure 1.14 shows the executing app.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 107: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 108: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 109: cshtp5_01

Step 5: Changing the Brush ColorClick the RadioButton labeled Red to change the brush color. Position the mouse over the white Canvas, then drag the mouse to draw with the brush.Draw flower petals, as shown in Fig. 1.15.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 110: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 111: cshtp5_01

Step 6: Changing the Brush Color and SizeClick the RadioButton labeled Green to change the brush color again. Then, click the RadioButton labeled Large to change the brush size. Draw grass and a flower stem, as shown in Fig. 1.16.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 112: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 113: cshtp5_01

Step 7: Finishing the DrawingClick the Blue and Medium RadioButtons. Draw raindrops, as shown in Fig. 1.17, to complete the drawing.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 114: cshtp5_01

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 115: cshtp5_01

Step 8: Stopping the AppWhen you run an app from Visual Studio, you can terminate it by clicking the stop button on the Visual Studio toolbar. Typically, when you’re done using a Windows 8 UI app like Painter, you don’t terminate the app. Instead you simply run another app. Windows 8 suspends the execution of the previous app you were running, but keeps it in memory in case you decide to return to the app.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.

Page 116: cshtp5_01

Windows may decide to terminate a suspended app to free up memory for executing other apps.

To explicitly shut down a Windows 8 UI app, simply drag from the top of the screen to the bottom or press Alt + F4.

©1992-2014 by Pearson Education, Inc. All Rights Reserved.