You are previewing Begin to Code with C#.
O'Reilly logo
Begin to Code with C#

Book Description

Become a C# programmer—and have fun doing it!

Start writing software that solves real problems, even if you have absolutely no programming experience! This friendly, easy, full-color book puts you in total control of your own learning, empowering you to build unique and useful programs. Microsoft has completely reinvented the beginning programmer’s tutorial, reflecting deep research into how today’s beginners learn, and why other books fall short. Begin to Code with C# is packed with innovations, from its “Snaps” prebuilt operations to its “Make Something Happen” projects. Whether you’re a total beginner or you’ve tried before, this guide will put the power, excitement, and fun of programming where it belongs: in your hands!

Easy, friendly, and you’re in control! Learn how to…

• Get the free tools you need to create modern programs

• Work with 150 sample programs that illustrate important concepts

• Use the sample programs as starting points for your own programs

• Explore exactly what happens when a program runs

• Approach program development with a professional perspective

• Use powerful productivity shortcuts built into Microsoft Visual Studio

• Master classes, interfaces, methods, and other essential concepts

• Organize programs so they’re easy to construct and improve

• Capture and respond to user input

• Store and manipulate many types of real-world data

• Create interactive games that are fun to play

• Build modern interfaces your users will love

• Test and debug your code—and avoid problems in the first place 

Table of Contents

  1. Cover
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. Contents at a glance
  6. Contents
  7. Introduction
    1. How this book fits together
      1. Part 1: Coding fundamentals
      2. Part 2: Advanced programming
      3. Part 3: Making games
      4. Part 4: Creating applications
    2. How you will learn
      1. Programs and Snaps
    3. Software and hardware
      1. Downloads
    4. Acknowledgments
    5. Errata, updates, & book support
    6. Free ebooks from Microsoft Press
    7. We want to hear from you
    8. Stay in touch
  8. Part 1: Programming fundamentals
    1. 1. Starting out
      1. Building a place to work
      2. Getting the tools and demos
      3. Using the tools
        1. Visual Studio projects and solutions
        2. Running a program with Visual Studio
        3. Stopping a program running in Visual Studio
        4. The MyProgram application
      4. What you have learned
    2. 2. What is programming?
      1. What makes a programmer?
        1. Programming and party planning
        2. Programming and problems
        3. Programmers and people
      2. Computers as data processors
        1. Machines and computers and us
        2. Making programs work
        3. Programs as data processors
      3. Data and information
      4. What you have learned
    3. 3. Writing programs
      1. C# program structure
        1. Identify resources
        2. Start a class definition
        3. Declare the StartProgram method
        4. Set the title and display a message
      2. Extra Snaps
        1. SpeakString
      3. Creating new program files
      4. Extra Snaps
        1. Delay
        2. SetTextColor
        3. SetTitleColor
        4. SetBackgroundColor
      5. Creating your own colors
      6. What you have learned
    4. 4. Working with data in a program
      1. Starting with variables
        1. Variables and computer storage
        2. Declaring a variable
        3. Simple assignment statements
      2. Using a variable in a program
        1. Assigning values in a declaration
        2. Adding strings together
      3. Working with numbers
        1. Whole numbers and real numbers
        2. Performing calculations
      4. Working with different types of data
        1. Converting numbers into text
      5. Whole numbers and real numbers in programs
        1. Variable types and expressions
        2. Precision and accuracy
        3. Converting types by casting
        4. Using casting on operands in an expression
        5. Types and errors
      6. Extra Snaps
        1. Weather snaps
        2. ThrowDice
      7. What you have learned
    5. 5. Making decisions in a program
      1. Understanding the Boolean type
        1. Declaring a Boolean variable
        2. Boolean expressions
      2. Using if constructions and operators
        1. Relational operators
        2. Equality operators
        3. Comparing strings
      3. Creating blocks of statements
        1. Local variables in blocks of code
      4. Creating complex conditions using logical operators
        1. Working with logic
      5. Adding comments to make a program clearer
      6. Funfair rides and programs
        1. Reading in numbers
        2. Building logic using if conditions
        3. Completing the program
      7. Working with program assets
        1. Asset management in Visual Studio
        2. Playing sound assets
        3. Displaying image content
      8. What you have learned
    6. 6. Repeating actions with loops
      1. Using a loop to make a pizza picker
        1. Counting selections
        2. Displaying the totals
        3. Getting user options
        4. Adding a while loop
      2. Performing input validation with a while loop
      3. Using Visual Studio to follow the execution of your programs
      4. Counting in a loop to make a times-table tutor
      5. Using a for loop construction
      6. Breaking out of loops
      7. Going back to the top of a loop by using continue
      8. Extra Snaps
        1. Voice input
        2. Secret data entry
      9. What you have learned
    7. 7. Using arrays
      1. Have an ice cream
        1. Storing the data in single variables
      2. Making an array
        1. Using an index
        2. Working with arrays
        3. Displaying the contents of the array by using a for loop
        4. Displaying a user menu
        5. Sorting an array using the Bubble Sort
        6. Finding the highest and lowest sales values
        7. Working out the total and the average sales
        8. Completing the program
      3. Multiple dimensions in arrays
        1. Using nested for loops to work with two-dimensional arrays
        2. Making test versions of programs
        3. Finding the length of an array dimension
      4. Using arrays as lookup tables
      5. What you have learned
  9. Part 2: Advanced programming
    1. 8. Using methods to simplify programs
      1. What makes a method?
        1. Adding a method to a class
        2. Feeding information to methods by using parameters
        3. Returning values from method calls
      2. Making a tiny contacts app
        1. Reading in contact details
        2. Storing contact information
        3. Using Windows local storage
        4. Using reference parameters to deliver results from a method call
        5. Displaying the contact details
      3. Adding IntelliSense comments to your methods
      4. What you have learned
    2. 9. Creating structured data types
      1. Storing music notes by using a structure
        1. Creating and declaring a structure
        2. Creating arrays of structure values
        3. Structures and methods
        4. Constructing structure values
        5. Making a music recorder
        6. Creating preset arrays
      2. Objects and responsibilities: Making a SongNote play itself
      3. Protecting values held in a structure
      4. Making a drawing program with Snaps
        1. Drawing dots on the screen
        2. Using the DrawDot Snap to draw a dot on the screen
        3. The SnapsCoordinate structure
        4. Using the GetDraggedCoordinate Snap to detect a drawing position
        5. Using the SetDrawingColor Snap to set the drawing color
        6. Using the ClearGraphics Snap to clear the screen
        7. The SnapsColor structure
      5. Creating enumerated types
      6. Making decisions with the switch construction
      7. Extra Snaps
        1. GetTappedCoordinate
        2. DrawLine
        3. GetScreenSize
        4. PickImage
      8. What you have learned
    3. 10. Classes and references
      1. Making a time tracker
        1. Creating a structure to hold contact information
        2. Using the this reference when working with objects
        3. Managing lots of contacts
        4. Making test data
        5. Designing the Time Tracker user interface
        6. Structuring the Time Tracker program
        7. Creating a new contact
        8. Finding customer details
        9. Adding minutes to a contact
        10. Display a summary
      2. Structures and classes
        1. Sorting and structures
        2. Sorting and references
        3. Reference and value types
        4. References and assignments
        5. Classes and constructors
        6. Arrays of class references
      3. From arrays to lists
        1. Working through lists of data
        2. Lists and the index value
        3. Lists of structures
      4. Storing data using JSON
        1. The Newtonsoft JSON library
        2. Storing and recovering lists
      5. Fetching data using XML
      6. What you have learned
    4. 11. Making solutions with objects
      1. Creating objects with integrity
        1. Protecting data held inside an object
        2. Providing Get and Set methods for private data
        3. Providing methods that reflect the use of an object
      2. Using properties to manage access to data
        1. Using properties to enforce business rules
      3. Managing the object construction process
        1. Catching and dealing with exceptions
        2. Creating user-friendly applications
      4. Saving drawings in files
        1. SaveGraphicsImageToFileAsPNG
        2. SaveGraphicsImageToLocalStoreAsPNG
        3. LoadGraphicsPNGImageFromLocalStore
        4. The DateTime structure
        5. Getting the current date and time
        6. Fading date and time displays
        7. Using the date and time to make a file name
        8. Creating a Drawing class
        9. Creating a list of drawings
        10. Making the drawing diary methods
      5. What you have learned
  10. Part 3: Making games
    1. 12. What makes a game?
      1. Creating a video game
        1. Games and game engines
        2. Games and sprites
      2. What you have learned
    2. 13. Creating gameplay
      1. Creating a player-controlled paddle
      2. Adding sound to games
      3. Displaying text in a game
        1. Making a complete game
      4. What you have learned
    3. 14. Games and object hierarchies
      1. Games and objects: Space Rockets in Space
        1. Constructing a star sprite that moves
        2. Allowing methods to be overridden
        3. Creating a moving star field
        4. Creating a rocket based on a MovingSprite
        5. Adding some aliens
      2. Designing a class hierarchy
      3. What you have learned
    4. 15. Games and software components
      1. Games and objects
        1. Creating cooperating objects
        2. Objects and state
        3. Interfaces and components
      2. What you have learned
  11. Index
  12. About the author
  13. Survey
  14. Code Snippets