introducing our language: c# - protobook.prototools.net/wp-content/uploads/2014/06/igdpd...

157
INTRODUCING OUR LANGUAGE: C# CHAPTER 17 1

Upload: others

Post on 28-Sep-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

INTRODUCING OUR LANGUAGE: C#

CHAPTER 17

1

Page 2: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics

2

Page 3: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics§ The Features of C#

2

Page 4: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics§ The Features of C#

– C# is a Compiled Language

2

Page 5: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics§ The Features of C#

– C# is a Compiled Language– C# is Managed Code

2

Page 6: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics§ The Features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed

2

Page 7: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics§ The Features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed– C# is Function Based

2

Page 8: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics§ The Features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed– C# is Function Based– C# is Object-Oriented

2

Page 9: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Topics§ The Features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed– C# is Function Based– C# is Object-Oriented

§ Reading and Understanding C# Syntax

2

Page 10: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

3

Page 11: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

3

Page 12: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

– Computer chips only understand machine language

3

Page 13: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

– Computer chips only understand machine language• 000000 00001 00010 00110 00000 100000

3

Page 14: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

– Computer chips only understand machine language• 000000 00001 00010 00110 00000 100000 • This is what punch cards were

3

Page 15: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

– Computer chips only understand machine language• 000000 00001 00010 00110 00000 100000 • This is what punch cards were

– Authoring languages were created to be an intermediary language between humans and computers

3

Page 16: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

– Computer chips only understand machine language• 000000 00001 00010 00110 00000 100000 • This is what punch cards were

– Authoring languages were created to be an intermediary language between humans and computers

– Two kinds of authoring languages:

3

Page 17: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

– Computer chips only understand machine language• 000000 00001 00010 00110 00000 100000 • This is what punch cards were

– Authoring languages were created to be an intermediary language between humans and computers

– Two kinds of authoring languages:• Interpreted

3

Page 18: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is a Compiled Language

– Computer chips only understand machine language• 000000 00001 00010 00110 00000 100000 • This is what punch cards were

– Authoring languages were created to be an intermediary language between humans and computers

– Two kinds of authoring languages:• Interpreted• Compiled

3

Page 19: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

4

Page 20: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

4

Page 21: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python

4

Page 22: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

4

Page 23: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

• Programmer writes the code

4

Page 24: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

• Programmer writes the code• An interpreter converts the code into machine language in real-time

4

Page 25: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

• Programmer writes the code• An interpreter converts the code into machine language in real-time

– Benefits

4

Page 26: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

• Programmer writes the code• An interpreter converts the code into machine language in real-time

– Benefits• Portability: Can run on any kind of computer as long as there's an

interpreter

4

Page 27: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

• Programmer writes the code• An interpreter converts the code into machine language in real-time

– Benefits• Portability: Can run on any kind of computer as long as there's an

interpreter

– Detriments

4

Page 28: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

• Programmer writes the code• An interpreter converts the code into machine language in real-time

– Benefits• Portability: Can run on any kind of computer as long as there's an

interpreter

– Detriments• Lack of Speed: The processing power used to interpret the code is

not spent on the game itself

4

Page 29: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Interpreted Languages

– e.g., JavaScript, PHP, and Python– Two-Step Process

• Programmer writes the code• An interpreter converts the code into machine language in real-time

– Benefits• Portability: Can run on any kind of computer as long as there's an

interpreter

– Detriments• Lack of Speed: The processing power used to interpret the code is

not spent on the game itself• Lack of Efficiency: Because the code can run on any computer, it's

not optimized for any specific computer

4

Page 30: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

5

Page 31: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

5

Page 32: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++

5

Page 33: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

5

Page 34: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code

5

Page 35: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language

5

Page 36: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language• Computer executes the code

5

Page 37: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language• Computer executes the code

– Benefits

5

Page 38: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language• Computer executes the code

– Benefits• Speed: Computer spends more processor power on the game itself

5

Page 39: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language• Computer executes the code

– Benefits• Speed: Computer spends more processor power on the game itself• Efficiency: Code is optimized for a specific processor architecture

5

Page 40: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language• Computer executes the code

– Benefits• Speed: Computer spends more processor power on the game itself• Efficiency: Code is optimized for a specific processor architecture

– Detriments

5

Page 41: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language• Computer executes the code

– Benefits• Speed: Computer spends more processor power on the game itself• Efficiency: Code is optimized for a specific processor architecture

– Detriments• Lack of Portability: Compiled for only one kind of machine

5

Page 42: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ Compiled Languages

– e.g., C#, Basic, Java, C++– Three-Step Process

• Programmer writes the code• Programmer uses a compiler to convert the code into machine

language• Computer executes the code

– Benefits• Speed: Computer spends more processor power on the game itself• Efficiency: Code is optimized for a specific processor architecture

– Detriments• Lack of Portability: Compiled for only one kind of machine• Extra Compilation Step

5

Page 43: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

6

Hierarchy of Computer Languages

Page 44: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

7

Page 45: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Managed Code

7

Page 46: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Managed Code

– Computers have a limited amount of Random Access Memory (RAM)

7

Page 47: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Managed Code

– Computers have a limited amount of Random Access Memory (RAM)

– Older compiled languages like BASIC and C++ require the programmer to manually allocate and deallocate RAM

7

Page 48: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Managed Code

– Computers have a limited amount of Random Access Memory (RAM)

– Older compiled languages like BASIC and C++ require the programmer to manually allocate and deallocate RAM

– In managed code, allocation and deallocation are handled automatically

7

Page 49: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Managed Code

– Computers have a limited amount of Random Access Memory (RAM)

– Older compiled languages like BASIC and C++ require the programmer to manually allocate and deallocate RAM

– In managed code, allocation and deallocation are handled automatically

– This makes it less likely that you will accidentally claim all of the memory

7

Page 50: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Managed Code

– Computers have a limited amount of Random Access Memory (RAM)

– Older compiled languages like BASIC and C++ require the programmer to manually allocate and deallocate RAM

– In managed code, allocation and deallocation are handled automatically

– This makes it less likely that you will accidentally claim all of the memory

• Doing so is known as a "memory leak"

7

Page 51: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

8

Page 52: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

8

Page 53: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra

8

Page 54: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5

8

Page 55: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5– x + 2 = ?

8

Page 56: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5– x + 2 = ?

§ Variables in computer languages can hold much more than just simple numbers

8

Page 57: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5– x + 2 = ?

§ Variables in computer languages can hold much more than just simple numbers

– Numbers

8

Page 58: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5– x + 2 = ?

§ Variables in computer languages can hold much more than just simple numbers

– Numbers– Words, sentences, paragraphs, novels…

8

Page 59: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5– x + 2 = ?

§ Variables in computer languages can hold much more than just simple numbers

– Numbers– Words, sentences, paragraphs, novels…– Images, sounds, 3D models, animations…

8

Page 60: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5– x + 2 = ?

§ Variables in computer languages can hold much more than just simple numbers

– Numbers– Words, sentences, paragraphs, novels…– Images, sounds, 3D models, animations…– Functions and methods

8

Page 61: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

VARIABLES IN COMPUTER LANGUAGES

§ A variable is a name that can hold a value

§ This concept is borrowed from algrbra– x = 5– x + 2 = ?

§ Variables in computer languages can hold much more than just simple numbers

– Numbers– Words, sentences, paragraphs, novels…– Images, sounds, 3D models, animations…– Functions and methods– Classes and GameObjects

8

Page 62: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

9

Page 63: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

9

Page 64: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

9

Page 65: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

9

Page 66: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

– A strongly typed language restricts the type of data that can be held by any variable

9

Page 67: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

– A strongly typed language restricts the type of data that can be held by any variable

• int x = 5;! – An int x can only hold an integer number

9

Page 68: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

– A strongly typed language restricts the type of data that can be held by any variable

• int x = 5;! – An int x can only hold an integer number• float y = 3.4f;! – A float y can only hold a floating point number

9

Page 69: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

– A strongly typed language restricts the type of data that can be held by any variable

• int x = 5;! – An int x can only hold an integer number• float y = 3.4f;! – A float y can only hold a floating point number

– Strong typing allows accurate syntax checking

9

Page 70: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

– A strongly typed language restricts the type of data that can be held by any variable

• int x = 5;! – An int x can only hold an integer number• float y = 3.4f;! – A float y can only hold a floating point number

– Strong typing allows accurate syntax checking• The compiler can check your code for correctness

9

Page 71: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

– A strongly typed language restricts the type of data that can be held by any variable

• int x = 5;! – An int x can only hold an integer number• float y = 3.4f;! – A float y can only hold a floating point number

– Strong typing allows accurate syntax checking• The compiler can check your code for correctness

– Strong typing also allows robust code-completion

9

Page 72: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Strongly Typed

– In a non-strongly typed language, a variable can hold any kind of data

• The same variable could hold a number one moment and an animation the next

– A strongly typed language restricts the type of data that can be held by any variable

• int x = 5;! – An int x can only hold an integer number• float y = 3.4f;! – A float y can only hold a floating point number

– Strong typing allows accurate syntax checking• The compiler can check your code for correctness

– Strong typing also allows robust code-completion• The code editor can guess what you want to type and auto-complete

9

Page 73: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

10

Page 74: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

10

Page 75: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands

10

Page 76: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

10

Page 77: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont

10

Page 78: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)

10

Page 79: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)3. At the intersection with I-405, take the 405 south for 2mi (3.2Km)

10

Page 80: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)3. At the intersection with I-405, take the 405 south for 2mi (3.2Km)4. Take the exit for Venice Blvd.

10

Page 81: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)3. At the intersection with I-405, take the 405 south for 2mi (3.2Km)4. Take the exit for Venice Blvd.5. Turn right onto Sawtelle Blvd.

10

Page 82: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)3. At the intersection with I-405, take the 405 south for 2mi (3.2Km)4. Take the exit for Venice Blvd.5. Turn right onto Sawtelle Blvd.6. My place is just north of Venice on Sawtelle.

10

Page 83: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)3. At the intersection with I-405, take the 405 south for 2mi (3.2Km)4. Take the exit for Venice Blvd.5. Turn right onto Sawtelle Blvd.6. My place is just north of Venice on Sawtelle.

– Functional languages allow the encapsulation of commands

10

Page 84: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)3. At the intersection with I-405, take the 405 south for 2mi (3.2Km)4. Take the exit for Venice Blvd.5. Turn right onto Sawtelle Blvd.6. My place is just north of Venice on Sawtelle.

– Functional languages allow the encapsulation of commands• "If you see a store on the way, please BuySomeMilk()."

10

Page 85: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Function Based

– Computer programs used to be just a series of commands– This was like giving driving directions to someone

1. From school, head north on Vermont2. Head west on I-10 for about 7.5 miles (about 12Km)3. At the intersection with I-405, take the 405 south for 2mi (3.2Km)4. Take the exit for Venice Blvd.5. Turn right onto Sawtelle Blvd.6. My place is just north of Venice on Sawtelle.

– Functional languages allow the encapsulation of commands• "If you see a store on the way, please BuySomeMilk()."• The BuySomeMilk() function encapsulates the many actions

involved in finding and purchasing milk.

10

Page 86: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#

11

Page 87: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

11

Page 88: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate

11

Page 89: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes

11

Page 90: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

11

Page 91: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

• Variables in classes are called fields

11

Page 92: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

• Variables in classes are called fields• Functions in classes are called methods

11

Page 93: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

• Variables in classes are called fields• Functions in classes are called methods

– This enables things like a flock of birds where each bird thinks for itself…

11

Page 94: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

• Variables in classes are called fields• Functions in classes are called methods

– This enables things like a flock of birds where each bird thinks for itself…

• …rather than being controlled by a single, monolithic program

11

Page 95: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

• Variables in classes are called fields• Functions in classes are called methods

– This enables things like a flock of birds where each bird thinks for itself…

• …rather than being controlled by a single, monolithic program

– Object-orientation also allows class inheritance

11

Page 96: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

• Variables in classes are called fields• Functions in classes are called methods

– This enables things like a flock of birds where each bird thinks for itself…

• …rather than being controlled by a single, monolithic program

– Object-orientation also allows class inheritance• A subclass can inherit the fields and methods of its superclass

11

Page 97: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Understanding the Features of C#§ C# is Object-Oriented

– Functions and data used to be separate– Object-oriented programming introduced classes– Classes combine functions and data into a single object

• Variables in classes are called fields• Functions in classes are called methods

– This enables things like a flock of birds where each bird thinks for itself…

• …rather than being controlled by a single, monolithic program

– Object-orientation also allows class inheritance• A subclass can inherit the fields and methods of its superclass• e.g., a Dog would inherit all the fields and methods of its superclass Mammal, which would in turn inherit from Animal

11

Page 98: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax

12

Page 99: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

Page 100: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

Page 101: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

Page 102: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

Page 103: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

Page 104: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

[Subject] [verb] [object].

Page 105: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

[Subject] [verb] [object].

[Object] [subject] [verb].

Page 106: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

[Subject] [verb] [object].

[Object] [subject] [verb].

[Subject] [object]. [verb]

Page 107: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

[Subject] [verb] [object].

[Object] [subject] [verb].

[Subject] [object]. [verb]

[verb] [Subject] [object].

Page 108: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

[Subject] [verb] [object].

[Object] [subject] [verb].

[Subject] [object]. [verb]

[verb] [Subject] [object].

§ Only one of these sentences is correct

Page 109: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

[Subject] [verb] [object].

[Object] [subject] [verb].

[Subject] [object]. [verb]

[verb] [Subject] [object].

§ Only one of these sentences is correct– Only one follows the rules of syntax of the English language

Page 110: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ All languages have syntax:

12

The dog barked at the squirrel.

At the squirrel the dog barked.

The dog at the squirrel. barked

barked The dog at the squirrel.

[Subject] [verb] [object].

[Object] [subject] [verb].

[Subject] [object]. [verb]

[verb] [Subject] [object].

§ Only one of these sentences is correct– Only one follows the rules of syntax of the English language

§ The other sentences have syntax errors

Page 111: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax

13

Page 112: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

13

Page 113: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;

13

Page 114: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;• Declares a variable named x of the type int

13

Page 115: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;• Declares a variable named x of the type int

– If a statement starts with a type, the second word of the statement becomes a new variable of that type

13

Page 116: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;• Declares a variable named x of the type int

– If a statement starts with a type, the second word of the statement becomes a new variable of that type

• Defines the value of x to be 5

13

Page 117: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;• Declares a variable named x of the type int

– If a statement starts with a type, the second word of the statement becomes a new variable of that type

• Defines the value of x to be 5– The = is used to assign values to variables

13

Page 118: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;• Declares a variable named x of the type int

– If a statement starts with a type, the second word of the statement becomes a new variable of that type

• Defines the value of x to be 5– The = is used to assign values to variables

• All C# statements end with a semicolon ( ; )

13

Page 119: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;• Declares a variable named x of the type int

– If a statement starts with a type, the second word of the statement becomes a new variable of that type

• Defines the value of x to be 5– The = is used to assign values to variables

• All C# statements end with a semicolon ( ; )– A semicolon is used because the period is already used in decimal

numbers

13

Page 120: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax

14

Page 121: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

14

Page 122: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;

14

Page 123: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;– int y = x * ( 3 + x );

14

Page 124: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;– int y = x * ( 3 + x );

• Declares a variable named y of the type int

14

Page 125: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;– int y = x * ( 3 + x );

• Declares a variable named y of the type int• Adds 3 + x for a value of 8 (because x = 5)

14

Page 126: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;– int y = x * ( 3 + x );

• Declares a variable named y of the type int• Adds 3 + x for a value of 8 (because x = 5)

– Just as in algebra, order of operations follows parentheses first

14

Page 127: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;– int y = x * ( 3 + x );

• Declares a variable named y of the type int• Adds 3 + x for a value of 8 (because x = 5)

– Just as in algebra, order of operations follows parentheses first

• Multiplies x * 8 for a value of 40 (5 * 8 = 40)

14

Page 128: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;– int y = x * ( 3 + x );

• Declares a variable named y of the type int• Adds 3 + x for a value of 8 (because x = 5)

– Just as in algebra, order of operations follows parentheses first

• Multiplies x * 8 for a value of 40 (5 * 8 = 40)• Defines the value of y to be 40

14

Page 129: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– int x = 5;– int y = x * ( 3 + x );

• Declares a variable named y of the type int• Adds 3 + x for a value of 8 (because x = 5)

– Just as in algebra, order of operations follows parentheses first

• Multiplies x * 8 for a value of 40 (5 * 8 = 40)• Defines the value of y to be 40• Ends with a semicolon ( ; )

14

Page 130: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax

15

Page 131: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

15

Page 132: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";

15

Page 133: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";• Declares a variable named greeting of the type string

15

Page 134: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";• Declares a variable named greeting of the type string

– strings can hold a series of characters like a word or novel

15

Page 135: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";• Declares a variable named greeting of the type string

– strings can hold a series of characters like a word or novel

• Defines the value of greeting to be "Hello World!"

15

Page 136: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";• Declares a variable named greeting of the type string

– strings can hold a series of characters like a word or novel

• Defines the value of greeting to be "Hello World!"– Anything between double quotes is a string literal, a value to be

assigned to a string variable

15

Page 137: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";• Declares a variable named greeting of the type string

– strings can hold a series of characters like a word or novel

• Defines the value of greeting to be "Hello World!"– Anything between double quotes is a string literal, a value to be

assigned to a string variable

• Ends with a semicolon ( ; )

15

Page 138: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax

16

Page 139: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

16

Page 140: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";

16

Page 141: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

16

Page 142: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

• Calls the function print()

16

Page 143: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

• Calls the function print()– When a function is called, it executes its actions

16

Page 144: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

• Calls the function print()– When a function is called, it executes its actions

• Passes the argument greeting into the function print()

16

Page 145: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

• Calls the function print()– When a function is called, it executes its actions

• Passes the argument greeting into the function print()– Some functions take arguments: data that changes how the function

acts

16

Page 146: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

• Calls the function print()– When a function is called, it executes its actions

• Passes the argument greeting into the function print()– Some functions take arguments: data that changes how the function

acts– The print() function will print the string greeting to the Console pane in

Unity

16

Page 147: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

• Calls the function print()– When a function is called, it executes its actions

• Passes the argument greeting into the function print()– Some functions take arguments: data that changes how the function

acts– The print() function will print the string greeting to the Console pane in

Unity– The Console pane will display "Hello World!"

16

Page 148: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Reading and Understanding C# Syntax§ C# statements also have syntax rules

– string greeting = "Hello World!";– print( greeting );

• Calls the function print()– When a function is called, it executes its actions

• Passes the argument greeting into the function print()– Some functions take arguments: data that changes how the function

acts– The print() function will print the string greeting to the Console pane in

Unity– The Console pane will display "Hello World!"

• Ends with a semicolon ( ; )

16

Page 149: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary

17

Page 150: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

17

Page 151: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

– C# is a Compiled Language

17

Page 152: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

– C# is a Compiled Language– C# is Managed Code

17

Page 153: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed

17

Page 154: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed– C# is Function Based

17

Page 155: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed– C# is Function Based– C# is Object-Oriented

17

Page 156: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed– C# is Function Based– C# is Object-Oriented

§ You learned to read and understand some C#

17

Page 157: INTRODUCING OUR LANGUAGE: C# - Protobook.prototools.net/wp-content/uploads/2014/06/IGDPD C17-Introdu… · – C# is a Compiled Language – C# is Managed Code – C# is Strongly

Chapter 17 – Summary§ You learned important features of C#

– C# is a Compiled Language– C# is Managed Code– C# is Strongly Typed– C# is Function Based– C# is Object-Oriented

§ You learned to read and understand some C#

§ In the next chapter, you'll write your first Unity C# program

17