SlideShare a Scribd company logo
1 of 34
Chapter 3 – Introduction to C# Programming Outline 3.1  Introduction 3.2  Simple Program: Printing a Line of Text 3.3  Another Simple Program: Adding Integers 3.4  Memory Concepts 3.5  Arithmetic 3.6  Decision Making: Equality and Relational Operators
3.1  Introduction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.2  Simple Program: Printing a line of text ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.2  Simple Program: Printing a line of text ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.2  Simple Program: Printing a line of text ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.2  Simple Program: Printing a line of text ,[object Object],[object Object],[object Object],[object Object],[object Object]
Welcome1.cs Program Output 1   // Fig. 3.1: Welcome1.cs 2   // A first program in C#. 3   4   using  System; 5   6   class  Welcome1 7   { 8   static   void  Main(  string [] args ) 9   { 10   Console.WriteLine(  "Welcome to C# Programming!"  ); 11   } 12   } Welcome to C# Programming!   These are two single line comments. They are ignored by the compiler and are only used to aid other programmers. They use the double slash (//) This is the using directive. It lets the compiler know that it should include the System namespace. This is a blank line. It means nothing to the compiler and is only used to add clarity to the program. This is the beginning of the Welcome1 class definition. It starts with the  class  keyword and then the name of the class. This is the start of the Main method. In this case it instructs the program to do everything This is a string of characters that Console.WriteLine instructs the compiler to output
3.2  Simple Program: Printing a Line of Text Fig. 3.2 Visual Studio .NET-generated console application.
3.2  Simple Program: Printing a Line of Text Fig. 3.3 Execution of the  Welcome1  program.
Welcome2.cs Program Output 1  // Fig. 3.4: Welcome2.cs 2  // Printing a line with multiple statements. 3  4  using  System; 5  6  class  Welcome2 7  { 8  static   void  Main(  string [] args ) 9  { 10  Console.Write(  "Welcome to "  ); 11   Console.WriteLine(  "C# Programming!"  ); 12  } 13  } Welcome to C# Programming!   Console.WriteLine will pick up where the line ends.  This will cause the output to be on one line even though it is on two in the code.
Welcome3.cs Program Output 1  // Fig. 3.5: Welcome3.cs 2  // Printing multiple lines with a single statement. 3  4  using  System; 5  6  class  Welcome3 7  { 8  static   void  Main(  string [] args ) 9  { 10   Console.WriteLine(  "WelcometoC#Programming!"  ); 11  } 12  } Welcome to C# Programming!   The  escape sequence is used to put output on the next line.  This causes the output to be on several lines even though it is only on one in the code.
3.2  Simple Program: Printing a Line of Text
Welcome4.cs Program Output 1  // Fig. 3.7: Welcome4.cs 2  // Printing multiple lines in a dialog Box. 3  4  using  System; 5   using  System.Windows.Forms; 6  7  class  Welcome4 8  { 9  static   void   Main (  string [] args ) 10  { 11   MessageBox.Show(  "WelcometoC#programming!"  ); 12  } 13  } The System.Windows.Forms namespace allows the programmer to use the MessageBox class. This will display the contents in a message box as opposed to in the console window.
3.2  Simple Program: Printing a Line of Text Fig. 3.8 Adding a reference to an assembly in Visual Studio .NET (part 1). Add Reference  dialogue
3.2  Simple Program: Printing a Line of Text Fig. 3.8 Adding a reference to an assembly in Visual Studio .NET (part 2). References   folder Solution Explorer System.Windows.Forms   reference
3.2  Simple Program: Printing a Line of Text Fig. 3.9 Internet Explorer’s GUI.  Text field Menu Button Label Menu bar
3.2  Simple Program: Printing a Line of Text Fig. 3.10 Dialog displayed by calling  MessageBox.Show .  OK  button allows the user to dismiss the dialog. Dialog is automatically sized to accommodate its contents. Mouse cursor Close box
3.3  Another Simple Program: Adding Integers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Addition.cs 1  // Fig. 3.11: Addition.cs 2  // An addition program. 3  4  using  System; 5  6   class  Addition 7  { 8  static   void  Main(  string [] args ) 9  { 10   string  firstNumber,  // first string entered by user 11   secondNumber;  // second string entered by user 12  13   int  number1,  // first number to add 14  number2,  // second number to add 15  sum;  // sum of number1 and number2 16  17  // prompt for and read first number from user as string 18   Console.Write(  "Please enter the first integer: "  ); 19   firstNumber = Console.ReadLine(); 20  21  // read second number from user as string 22  Console.Write(  "Please enter the second integer: "  ); 23  secondNumber = Console.ReadLine(); 24  25  // convert numbers from type string to type int 26   number1 = Int32.Parse( firstNumber ); 27  number2 = Int32.Parse( secondNumber ); 28  29  // add numbers 30   sum = number1 + number2; 31  This is the start of class Addition Two string variables defined over two lines The comment after the declaration is used to briefly state the variable purpose These are three  int s that are declared over several lines and only use one semicolon. Each is separated by a coma. Console.ReadLine is used to take the users input and place it into a variable. This line is considered a prompt because it asks the user to input data. Int32.Parse is used to convert the given string into an integer. It is then stored in a variable. The two numbers are added and stored in the variable sum.
Addition.cs Program Output 32  // display results 33   Console.WriteLine(  "The sum is {0}." , sum ); 34  35  }  // end method Main 36  37  }  // end class Addition Please enter the first integer: 45   Please enter the second integer: 72   The sum is 117. Putting a variable out through Console.WriteLine is done by placing the variable after the text while using a marked place to show where the variable should be placed.
3.4  Memory Concepts ,[object Object],[object Object],[object Object],[object Object],[object Object]
3.4  Memory Concepts Fig. 3.12 Memory location showing name and value of variable  number1 .  number1 45
3.5  Arithmetic ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.5  Arithmetic ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.4  Memory Concepts Fig. 3.13 Memory locations after values for variables  number1  and  number2  have been input.  number1 45 number2 72
3.4  Memory Concepts Fig. 3.14 Memory locations after a calculation.  number1 45 number2 72 sum 117
3.5  Arithmetic x y
3.5  Arithmetic
3.5  Arithmetic Fig. 3.17 Order in which a second-degree polynomial is evaluated.  Step 1. Step 2. Step 5. Step 3. Step 4. Step 6. y = 2 * 5 * 5 + 3 * 5 + 7; 2 * 5 is 10  (Leftmost multiplication) y = 10 * 5 + 3 * 5 + 7; 10 * 5 is 50  (Leftmost multiplication) y = 50 + 3 * 5 + 7; 3 * 5 is 15  (Multiplication before addition) y = 50 + 15 + 7; 50 + 15 is 65  (Leftmost addition) y = 65 + 7; 65 + 7 is 72  (Last addition) y = 72;  (Last operation—place  72  into  y )
3.6  Decision Making: Equality and Relational Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
3.6  Decision Making: Equality and Relational Operators
Comparison.cs 1  // Fig. 3.19: Comparison.cs 2  // Using if statements, relational operators and equality 3  // operators. 4  5  using  System; 6  7  class  Comparison 8  { 9  static void  Main(  string [] args ) 10  { 11  int  number1,  // first number to compare 12  number2;  // second number to compare 13  14  // read in first number from user 15  Console.Write(  &quot;Please enter first integer: &quot;  ); 16   number1 = Int32.Parse( Console.ReadLine() ); 17  18  // read in second number from user 19  Console.Write(  &quot;Please enter second integer: &quot;  ); 20  number2 = Int32.Parse( Console.ReadLine() ); 21  22  if  ( number1 == number2 ) 23   Console.WriteLine( number1 +  &quot; == &quot;  + number2 ); 24  25  if  ( number1 != number2 ) 26   Console.WriteLine( number1 +  &quot; != &quot;  + number2 ); 27  28  if  ( number1 < number2 ) 29   Console.WriteLine( number1 +  &quot; < &quot;  + number2 ); 30  31  if  ( number1 > number2 ) 32   Console.WriteLine( number1 +  &quot; > &quot;  +  number2 ); 33  Combining these two methods eliminates the need for a temporary string variable. If number1 is the same as number2 this line is preformed If number1 does not equal number2 this line of code is executed. If number1 is less than number2 the program will use this line If number1 is greater than number2 this line will be preformed
Comparison.cs Program Output 34  if  ( number1 <= number2 ) 35  Console.WriteLine( number1 +  &quot; <= &quot;  + number2 ); 36  37  if  ( number1 >= number2 ) 38  Console.WriteLine( number1 +  &quot; >= &quot;  + number2 ); 39  40  }  // end method Main 41  42  }  // end class Comparison Please enter first integer: 2000   Please enter second integer: 1000 2000 != 1000 2000 > 1000 2000 >= 1000 Please enter first integer: 1000   Please enter second integer: 2000 1000 != 2000 1000 < 2000 1000 <= 2000 Please enter first integer: 1000   Please enter second integer: 1000 1000 == 1000 1000 <= 1000 1000 >= 1000 If number1 is less than or equal to number2 then this code will be used Lastly if number1 is greater than or equal to number2 then this code will be executed
3.6  Decision Making: Equality and Relational Operators

More Related Content

Viewers also liked

Hammertoss: Proof of concept in C#
Hammertoss: Proof of concept in C#Hammertoss: Proof of concept in C#
Hammertoss: Proof of concept in C#Salvatore Saeli
 
Tips from angular js users anonymous
Tips from angular js users anonymousTips from angular js users anonymous
Tips from angular js users anonymousOleg Podsechin
 
Csphtp1 13
Csphtp1 13Csphtp1 13
Csphtp1 13HUST
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05HUST
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16HUST
 
Linux porting
Linux portingLinux porting
Linux portingerali007
 
Os cambios na nosa Terra
Os cambios na nosa TerraOs cambios na nosa Terra
Os cambios na nosa Terraelvira3
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09HUST
 
Hang sondoongcavern
Hang sondoongcavernHang sondoongcavern
Hang sondoongcavernholly625
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08HUST
 
Csphtp1 17
Csphtp1 17Csphtp1 17
Csphtp1 17HUST
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18HUST
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20HUST
 
1 ingles lista reposicao
1 ingles lista reposicao1 ingles lista reposicao
1 ingles lista reposicaoNathália Raggi
 
Csphtp1 21
Csphtp1 21Csphtp1 21
Csphtp1 21HUST
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06HUST
 
Towards an industrial Web of Things
Towards an industrial Web of ThingsTowards an industrial Web of Things
Towards an industrial Web of ThingsOlivier Liechti
 
Csphtp1 11
Csphtp1 11Csphtp1 11
Csphtp1 11HUST
 

Viewers also liked (20)

Hammertoss: Proof of concept in C#
Hammertoss: Proof of concept in C#Hammertoss: Proof of concept in C#
Hammertoss: Proof of concept in C#
 
Tips from angular js users anonymous
Tips from angular js users anonymousTips from angular js users anonymous
Tips from angular js users anonymous
 
Csphtp1 13
Csphtp1 13Csphtp1 13
Csphtp1 13
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16
 
Linux porting
Linux portingLinux porting
Linux porting
 
Ntd intro to electronics
Ntd   intro to electronicsNtd   intro to electronics
Ntd intro to electronics
 
Os cambios na nosa Terra
Os cambios na nosa TerraOs cambios na nosa Terra
Os cambios na nosa Terra
 
Csphtp1 09
Csphtp1 09Csphtp1 09
Csphtp1 09
 
Hang sondoongcavern
Hang sondoongcavernHang sondoongcavern
Hang sondoongcavern
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 
Csphtp1 17
Csphtp1 17Csphtp1 17
Csphtp1 17
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
Sabana de medicamentos para hacer
Sabana de medicamentos para hacerSabana de medicamentos para hacer
Sabana de medicamentos para hacer
 
Csphtp1 20
Csphtp1 20Csphtp1 20
Csphtp1 20
 
1 ingles lista reposicao
1 ingles lista reposicao1 ingles lista reposicao
1 ingles lista reposicao
 
Csphtp1 21
Csphtp1 21Csphtp1 21
Csphtp1 21
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
Towards an industrial Web of Things
Towards an industrial Web of ThingsTowards an industrial Web of Things
Towards an industrial Web of Things
 
Csphtp1 11
Csphtp1 11Csphtp1 11
Csphtp1 11
 

Similar to C# Chapter 3 Introduction to Programming Outline

Chapter03 Ppt
Chapter03 PptChapter03 Ppt
Chapter03 PptOsama Yaseen
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic ProgrammingOsama Yaseen
 
visualbasicprograming
visualbasicprogramingvisualbasicprograming
visualbasicprogramingdhi her
 
C chap02
C chap02C chap02
C chap02Kamran
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
Chapter0002222programming language2.pptx
Chapter0002222programming language2.pptxChapter0002222programming language2.pptx
Chapter0002222programming language2.pptxstephen972973
 
Chapter03_PPT.ppt
Chapter03_PPT.pptChapter03_PPT.ppt
Chapter03_PPT.pptDrRajeswari5
 
C# ProgrammingInstructions are as follows.I need to use the Cons.pdf
C# ProgrammingInstructions are as follows.I need to use the Cons.pdfC# ProgrammingInstructions are as follows.I need to use the Cons.pdf
C# ProgrammingInstructions are as follows.I need to use the Cons.pdffaxteldelhi
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Vivek Singh
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 

Similar to C# Chapter 3 Introduction to Programming Outline (20)

Chapter03 Ppt
Chapter03 PptChapter03 Ppt
Chapter03 Ppt
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Visual programming
Visual programmingVisual programming
Visual programming
 
visualbasicprograming
visualbasicprogramingvisualbasicprograming
visualbasicprograming
 
C chap02
C chap02C chap02
C chap02
 
C chap02
C chap02C chap02
C chap02
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
Chapter0002222programming language2.pptx
Chapter0002222programming language2.pptxChapter0002222programming language2.pptx
Chapter0002222programming language2.pptx
 
Chapter03_PPT.ppt
Chapter03_PPT.pptChapter03_PPT.ppt
Chapter03_PPT.ppt
 
C# ProgrammingInstructions are as follows.I need to use the Cons.pdf
C# ProgrammingInstructions are as follows.I need to use the Cons.pdfC# ProgrammingInstructions are as follows.I need to use the Cons.pdf
C# ProgrammingInstructions are as follows.I need to use the Cons.pdf
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part2
C programming part2C programming part2
C programming part2
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 

More from HUST

Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23HUST
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24HUST
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24HUST
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22HUST
 
Csphtp1 19
Csphtp1 19Csphtp1 19
Csphtp1 19HUST
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15HUST
 
Csphtp1 14
Csphtp1 14Csphtp1 14
Csphtp1 14HUST
 
Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12HUST
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10HUST
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07HUST
 
Csphtp1 02
Csphtp1 02Csphtp1 02
Csphtp1 02HUST
 
Csphtp1 01
Csphtp1 01Csphtp1 01
Csphtp1 01HUST
 
Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23HUST
 

More from HUST (13)

Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24
 
Csphtp1 24
Csphtp1 24Csphtp1 24
Csphtp1 24
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22
 
Csphtp1 19
Csphtp1 19Csphtp1 19
Csphtp1 19
 
Csphtp1 15
Csphtp1 15Csphtp1 15
Csphtp1 15
 
Csphtp1 14
Csphtp1 14Csphtp1 14
Csphtp1 14
 
Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07
 
Csphtp1 02
Csphtp1 02Csphtp1 02
Csphtp1 02
 
Csphtp1 01
Csphtp1 01Csphtp1 01
Csphtp1 01
 
Csphtp1 23
Csphtp1 23Csphtp1 23
Csphtp1 23
 

Recently uploaded

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Recently uploaded (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 âś“Call Girls In Kalyan ( Mumbai ) secure service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

C# Chapter 3 Introduction to Programming Outline

  • 1. Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line of Text 3.3 Another Simple Program: Adding Integers 3.4 Memory Concepts 3.5 Arithmetic 3.6 Decision Making: Equality and Relational Operators
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Welcome1.cs Program Output 1 // Fig. 3.1: Welcome1.cs 2 // A first program in C#. 3 4 using System; 5 6 class Welcome1 7 { 8 static void Main( string [] args ) 9 { 10 Console.WriteLine( &quot;Welcome to C# Programming!&quot; ); 11 } 12 } Welcome to C# Programming! These are two single line comments. They are ignored by the compiler and are only used to aid other programmers. They use the double slash (//) This is the using directive. It lets the compiler know that it should include the System namespace. This is a blank line. It means nothing to the compiler and is only used to add clarity to the program. This is the beginning of the Welcome1 class definition. It starts with the class keyword and then the name of the class. This is the start of the Main method. In this case it instructs the program to do everything This is a string of characters that Console.WriteLine instructs the compiler to output
  • 8. 3.2 Simple Program: Printing a Line of Text Fig. 3.2 Visual Studio .NET-generated console application.
  • 9. 3.2 Simple Program: Printing a Line of Text Fig. 3.3 Execution of the Welcome1 program.
  • 10. Welcome2.cs Program Output 1 // Fig. 3.4: Welcome2.cs 2 // Printing a line with multiple statements. 3 4 using System; 5 6 class Welcome2 7 { 8 static void Main( string [] args ) 9 { 10 Console.Write( &quot;Welcome to &quot; ); 11 Console.WriteLine( &quot;C# Programming!&quot; ); 12 } 13 } Welcome to C# Programming! Console.WriteLine will pick up where the line ends. This will cause the output to be on one line even though it is on two in the code.
  • 11. Welcome3.cs Program Output 1 // Fig. 3.5: Welcome3.cs 2 // Printing multiple lines with a single statement. 3 4 using System; 5 6 class Welcome3 7 { 8 static void Main( string [] args ) 9 { 10 Console.WriteLine( &quot;WelcometoC#Programming!&quot; ); 11 } 12 } Welcome to C# Programming! The escape sequence is used to put output on the next line. This causes the output to be on several lines even though it is only on one in the code.
  • 12. 3.2 Simple Program: Printing a Line of Text
  • 13. Welcome4.cs Program Output 1 // Fig. 3.7: Welcome4.cs 2 // Printing multiple lines in a dialog Box. 3 4 using System; 5 using System.Windows.Forms; 6 7 class Welcome4 8 { 9 static void Main ( string [] args ) 10 { 11 MessageBox.Show( &quot;WelcometoC#programming!&quot; ); 12 } 13 } The System.Windows.Forms namespace allows the programmer to use the MessageBox class. This will display the contents in a message box as opposed to in the console window.
  • 14. 3.2 Simple Program: Printing a Line of Text Fig. 3.8 Adding a reference to an assembly in Visual Studio .NET (part 1). Add Reference dialogue
  • 15. 3.2 Simple Program: Printing a Line of Text Fig. 3.8 Adding a reference to an assembly in Visual Studio .NET (part 2). References folder Solution Explorer System.Windows.Forms reference
  • 16. 3.2 Simple Program: Printing a Line of Text Fig. 3.9 Internet Explorer’s GUI. Text field Menu Button Label Menu bar
  • 17. 3.2 Simple Program: Printing a Line of Text Fig. 3.10 Dialog displayed by calling MessageBox.Show . OK button allows the user to dismiss the dialog. Dialog is automatically sized to accommodate its contents. Mouse cursor Close box
  • 18.
  • 19. Addition.cs 1 // Fig. 3.11: Addition.cs 2 // An addition program. 3 4 using System; 5 6 class Addition 7 { 8 static void Main( string [] args ) 9 { 10 string firstNumber, // first string entered by user 11 secondNumber; // second string entered by user 12 13 int number1, // first number to add 14 number2, // second number to add 15 sum; // sum of number1 and number2 16 17 // prompt for and read first number from user as string 18 Console.Write( &quot;Please enter the first integer: &quot; ); 19 firstNumber = Console.ReadLine(); 20 21 // read second number from user as string 22 Console.Write( &quot;Please enter the second integer: &quot; ); 23 secondNumber = Console.ReadLine(); 24 25 // convert numbers from type string to type int 26 number1 = Int32.Parse( firstNumber ); 27 number2 = Int32.Parse( secondNumber ); 28 29 // add numbers 30 sum = number1 + number2; 31 This is the start of class Addition Two string variables defined over two lines The comment after the declaration is used to briefly state the variable purpose These are three int s that are declared over several lines and only use one semicolon. Each is separated by a coma. Console.ReadLine is used to take the users input and place it into a variable. This line is considered a prompt because it asks the user to input data. Int32.Parse is used to convert the given string into an integer. It is then stored in a variable. The two numbers are added and stored in the variable sum.
  • 20. Addition.cs Program Output 32 // display results 33 Console.WriteLine( &quot;The sum is {0}.&quot; , sum ); 34 35 } // end method Main 36 37 } // end class Addition Please enter the first integer: 45   Please enter the second integer: 72   The sum is 117. Putting a variable out through Console.WriteLine is done by placing the variable after the text while using a marked place to show where the variable should be placed.
  • 21.
  • 22. 3.4 Memory Concepts Fig. 3.12 Memory location showing name and value of variable number1 . number1 45
  • 23.
  • 24.
  • 25. 3.4 Memory Concepts Fig. 3.13 Memory locations after values for variables number1 and number2 have been input. number1 45 number2 72
  • 26. 3.4 Memory Concepts Fig. 3.14 Memory locations after a calculation. number1 45 number2 72 sum 117
  • 29. 3.5 Arithmetic Fig. 3.17 Order in which a second-degree polynomial is evaluated. Step 1. Step 2. Step 5. Step 3. Step 4. Step 6. y = 2 * 5 * 5 + 3 * 5 + 7; 2 * 5 is 10 (Leftmost multiplication) y = 10 * 5 + 3 * 5 + 7; 10 * 5 is 50 (Leftmost multiplication) y = 50 + 3 * 5 + 7; 3 * 5 is 15 (Multiplication before addition) y = 50 + 15 + 7; 50 + 15 is 65 (Leftmost addition) y = 65 + 7; 65 + 7 is 72 (Last addition) y = 72; (Last operation—place 72 into y )
  • 30.
  • 31. 3.6 Decision Making: Equality and Relational Operators
  • 32. Comparison.cs 1 // Fig. 3.19: Comparison.cs 2 // Using if statements, relational operators and equality 3 // operators. 4 5 using System; 6 7 class Comparison 8 { 9 static void Main( string [] args ) 10 { 11 int number1, // first number to compare 12 number2; // second number to compare 13 14 // read in first number from user 15 Console.Write( &quot;Please enter first integer: &quot; ); 16 number1 = Int32.Parse( Console.ReadLine() ); 17 18 // read in second number from user 19 Console.Write( &quot;Please enter second integer: &quot; ); 20 number2 = Int32.Parse( Console.ReadLine() ); 21 22 if ( number1 == number2 ) 23 Console.WriteLine( number1 + &quot; == &quot; + number2 ); 24 25 if ( number1 != number2 ) 26 Console.WriteLine( number1 + &quot; != &quot; + number2 ); 27 28 if ( number1 < number2 ) 29 Console.WriteLine( number1 + &quot; < &quot; + number2 ); 30 31 if ( number1 > number2 ) 32 Console.WriteLine( number1 + &quot; > &quot; + number2 ); 33 Combining these two methods eliminates the need for a temporary string variable. If number1 is the same as number2 this line is preformed If number1 does not equal number2 this line of code is executed. If number1 is less than number2 the program will use this line If number1 is greater than number2 this line will be preformed
  • 33. Comparison.cs Program Output 34 if ( number1 <= number2 ) 35 Console.WriteLine( number1 + &quot; <= &quot; + number2 ); 36 37 if ( number1 >= number2 ) 38 Console.WriteLine( number1 + &quot; >= &quot; + number2 ); 39 40 } // end method Main 41 42 } // end class Comparison Please enter first integer: 2000   Please enter second integer: 1000 2000 != 1000 2000 > 1000 2000 >= 1000 Please enter first integer: 1000   Please enter second integer: 2000 1000 != 2000 1000 < 2000 1000 <= 2000 Please enter first integer: 1000   Please enter second integer: 1000 1000 == 1000 1000 <= 1000 1000 >= 1000 If number1 is less than or equal to number2 then this code will be used Lastly if number1 is greater than or equal to number2 then this code will be executed
  • 34. 3.6 Decision Making: Equality and Relational Operators