Microsoft Visual C# 2013 Step by Step

Book description

Your hands-on guide to Visual C# fundamentals

Expand your expertise—and teach yourself the fundamentals of Microsoft Visual C# 2013. If you have previous programming experience but are new to Visual C# 2013, this tutorial delivers the step-by-step guidance and coding exercises you need to master core topics and techniques.

Discover how to:

  • Create and debug C# applications in Visual Studio 2013

  • Work with variables, identifiers, statements, operators, and methods

  • Create interfaces and define abstract classes

  • Write robust code that can catch and handle exceptions

  • Display and edit data using data binding with Microsoft ADO.NET Entity Framework

  • Respond to user input and touchscreen gestures

  • Handle events arising from multiple sources

  • Develop your first Windows 8.1 apps

  • Table of contents

    1. Introduction
      1. Who should read this book
      2. Who should not read this book
      3. Organization of this book
        1. Finding your best starting point in this book
      4. Conventions and features in this book
      5. System requirements
      6. Code samples
        1. Installing the code samples
        2. Using the code samples
      7. Acknowledgments
      8. Errata and book support
      9. We want to hear from you
      10. Stay in touch
    2. I. Introducing Microsoft Visual C# and Microsoft Visual Studio 2013
      1. 1. Welcome to C#
        1. Beginning programming with the Visual Studio 2013 environment
        2. Writing your first program
        3. Using namespaces
        4. Creating a graphical application
          1. Examining the Windows Store app
          2. Examining the WPF application
          3. Adding code to the graphical application
        5. Summary
        6. Quick Reference
      2. 2. Working with variables, operators, and expressions
        1. Understanding statements
        2. Using identifiers
          1. Identifying keywords
        3. Using variables
          1. Naming variables
          2. Declaring variables
        4. Working with primitive data types
          1. Unassigned local variables
          2. Displaying primitive data type values
        5. Using arithmetic operators
          1. Operators and types
          2. Examining arithmetic operators
          3. Controlling precedence
          4. Using associativity to evaluate expressions
          5. Associativity and the assignment operator
        6. Incrementing and decrementing variables
          1. Prefix and postfix
        7. Declaring implicitly typed local variables
        8. Summary
        9. Quick Reference
      3. 3. Writing methods and applying scope
        1. Creating methods
          1. Declaring a method
          2. Returning data from a method
          3. Calling methods
            1. Specifying the method call syntax
        2. Applying scope
          1. Defining local scope
          2. Defining class scope
          3. Overloading methods
        3. Writing methods
        4. Using optional parameters and named arguments
          1. Defining optional parameters
          2. Passing named arguments
          3. Resolving ambiguities with optional parameters and named arguments
        5. Summary
        6. Quick reference
      4. 4. Using decision statements
        1. Declaring Boolean variables
        2. Using Boolean operators
          1. Understanding equality and relational operators
          2. Understanding conditional logical operators
          3. Short-circuiting
          4. Summarizing operator precedence and associativity
        3. Using if statements to make decisions
          1. Understanding if statement syntax
          2. Using blocks to group statements
          3. Cascading if statements
        4. Using switch statements
          1. Understanding switch statement syntax
          2. Following the switch statement rules
        5. Summary
        6. Quick reference
      5. 5. Using compound assignment and iteration statements
        1. Using compound assignment operators
        2. Writing while statements
        3. Writing for Statements
          1. Understanding for statement scope
        4. Writing do statements
        5. Summary
        6. Quick reference
      6. 6. Managing errors and exceptions
        1. Coping with errors
        2. Trying code and catching exceptions
          1. Unhandled Exceptions
          2. Using multiple catch handlers
          3. Catching multiple exceptions
          4. Propagating exceptions
        3. Using checked and unchecked integer arithmetic
          1. Writing checked statements
          2. Writing checked expressions
        4. Throwing exceptions
        5. Using a finally block
        6. Summary
        7. Quick reference
    3. II. Understanding the C# object model
      1. 7. Creating and managing classes and objects
        1. Understanding classification
        2. The purpose of encapsulation
        3. Defining and using a class
        4. Controlling accessibility
          1. Working with constructors
          2. Overloading constructors
        5. Understanding static methods and data
          1. Creating a shared field
          2. Creating a static field by using the const keyword
          3. Understanding static classes
          4. Anonymous classes
        6. Summary
        7. Quick reference
      2. 8. Understanding values and references
        1. Copying value type variables and classes
        2. Understanding null values and nullable types
          1. Using nullable types
          2. Understanding the properties of nullable types
        3. Using ref and out parameters
          1. Creating ref parameters
          2. Creating out parameters
        4. How computer memory is organized
          1. Using the stack and the heap
        5. The System.Object class
        6. Boxing
        7. Unboxing
        8. Casting data safely
          1. The is operator
          2. The as operator
        9. Summary
        10. Quick reference
      3. 9. Creating value types with enumerations and structures
        1. Working with enumerations
          1. Declaring an enumeration
          2. Using an enumeration
          3. Choosing enumeration literal values
          4. Choosing an enumeration’s underlying type
        2. Working with structures
          1. Declaring a structure
          2. Understanding structure and class differences
          3. Declaring structure variables
          4. Understanding structure initialization
          5. Copying structure variables
        3. Summary
        4. Quick reference
      4. 10. Using arrays
        1. Declaring and creating an array
          1. Declaring array variables
          2. Creating an array instance
        2. Populating and using an array
          1. Creating an implicitly typed array
          2. Accessing an individual array element
          3. Iterating through an array
          4. Passing arrays as parameters and return values for a method
        3. Copying arrays
        4. Using multidimensional arrays
          1. Creating jagged arrays
        5. Summary
        6. Quick reference
      5. 11. Understanding parameter arrays
        1. Overloading—a recap
        2. Using array arguments
          1. Declaring a params Array
          2. Using params object[ ]
          3. Using a params array
        3. Comparing parameter arrays and optional parameters
        4. Summary
        5. Quick reference
      6. 12. Working with inheritance
        1. What is inheritance?
        2. Using inheritance
          1. The System.Object class revisited
          2. Calling base class constructors
          3. Assigning classes
          4. Declaring new methods
          5. Declaring virtual methods
          6. Declaring override methods
          7. Understanding protected access
        3. Understanding extension methods
        4. Summary
        5. Quick reference
      7. 13. Creating interfaces and defining abstract classes
        1. Understanding interfaces
          1. Defining an interface
          2. Implementing an interface
          3. Referencing a class through its interface
          4. Working with multiple interfaces
          5. Explicitly implementing an interface
          6. Interface restrictions
          7. Defining and using interfaces
        2. Abstract classes
          1. Abstract methods
        3. Sealed classes
          1. Sealed methods
          2. Implementing and using an abstract class
        4. Summary
        5. Quick reference
      8. 14. Using garbage collection and resource management
        1. The life and times of an object
          1. Writing destructors
          2. Why use the garbage collector?
          3. How does the garbage collector work?
          4. Recommendations
        2. Resource management
          1. Disposal methods
          2. Exception-safe disposal
          3. The using statement and the IDisposable interface
          4. Calling the Dispose method from a destructor
        3. Implementing exception-safe disposal
        4. Summary
        5. Quick reference
    4. III. Defining extensible types with C#
      1. 15. Implementing properties to access fields
        1. Implementing encapsulation by using methods
        2. What are properties?
          1. Using properties
          2. Read-only properties
          3. Write-only properties
          4. Property accessibility
        3. Understanding the property restrictions
        4. Declaring interface properties
          1. Replacing methods with properties
        5. Generating automatic properties
        6. Initializing objects by using properties
        7. Summary
        8. Quick reference
      2. 16. Using indexers
        1. What is an indexer?
          1. An example that doesn’t use indexers
          2. The same example using indexers
          3. Understanding indexer accessors
          4. Comparing indexers and arrays
        2. Indexers in interfaces
        3. Using indexers in a Windows application
        4. Summary
        5. Quick reference
      3. 17. Introducing generics
        1. The problem with the object type
        2. The generics solution
          1. Generics vs. generalized classes
          2. Generics and constraints
        3. Creating a generic class
          1. The theory of binary trees
          2. Building a binary tree class by using generics
        4. Creating a generic method
          1. Defining a generic method to build a binary tree
        5. Variance and generic interfaces
          1. Covariant interfaces
          2. Contravariant interfaces
        6. Summary
        7. Quick reference
      4. 18. Using collections
        1. What are collection classes?
          1. The List<T> collection class
          2. The LinkedList<T> collection class
          3. The Queue<T> collection class
          4. The Stack<T> collection class
          5. The Dictionary<TKey, TValue> collection class
          6. The SortedList<TKey, TValue> collection class
          7. The HashSet<T> collection class
        2. Using collection initializers
        3. The Find methods, predicates, and lambda expressions
        4. Comparing arrays and collections
          1. Using collection classes to play cards
        5. Summary
        6. Quick reference
      5. 19. Enumerating collections
        1. Enumerating the elements in a collection
          1. Manually implementing an enumerator
          2. Implementing the IEnumerable interface
        2. Implementing an enumerator by using an iterator
          1. A simple iterator
          2. Defining an enumerator for the Tree<TItem> class by using an iterator
        3. Summary
        4. Quick reference
      6. 20. Decoupling application logic and handling events
        1. Understanding delegates
          1. Examples of delegates in the .NET Framework class library
          2. The automated factory scenario
          3. Implementing the factory control system without using delegates
          4. Implementing the factory by using a delegate
          5. Declaring and using delegates
        2. Lambda expressions and delegates
          1. Creating a method adapter
          2. The forms of lambda expressions
        3. Enabling notifications by using events
          1. Declaring an event
          2. Subscribing to an event
          3. Unsubscribing from an event
          4. Raising an event
        4. Understanding user interface events
          1. Using events
        5. Summary
        6. Quick reference
      7. 21. Querying in-memory data by using query expressions
        1. What is Language-Integrated Query?
        2. Using LINQ in a C# application
          1. Selecting data
          2. Filtering data
          3. Ordering, grouping, and aggregating data
          4. Joining data
          5. Using query operators
          6. Querying data in Tree<TItem> objects
          7. LINQ and deferred evaluation
        3. Summary
        4. Quick reference
      8. 22. Operator overloading
        1. Understanding operators
          1. Operator constraints
          2. Overloaded operators
          3. Creating symmetric operators
        2. Understanding compound assignment evaluation
        3. Declaring increment and decrement operators
        4. Comparing operators in structures and classes
        5. Defining operator pairs
        6. Implementing operators
        7. Understanding conversion operators
          1. Providing built-in conversions
          2. Implementing user-defined conversion operators
          3. Creating symmetric operators, revisited
          4. Writing conversion operators
        8. Summary
        9. Quick reference
    5. IV. Building professional Windows 8.1 applications with C#
      1. 23. Improving throughput by using tasks
        1. Why perform multitasking by using parallel processing?
          1. The rise of the multicore processor
        2. Implementing multitasking by using the Microsoft .NET Framework
          1. Tasks, threads, and the ThreadPool
          2. Creating, running, and controlling tasks
          3. Using the Task class to implement parallelism
          4. Abstracting tasks by using the Parallel class
          5. When not to use the Parallel class
        3. Canceling tasks and handling exceptions
          1. The mechanics of cooperative cancellation
          2. Using continuations with canceled and faulted tasks
        4. Summary
        5. Quick reference
      2. 24. Improving response time by performing asynchronous operations
        1. Implementing asynchronous methods
          1. Defining asynchronous methods: the problem
          2. Defining asynchronous methods: the solution
          3. Defining asynchronous methods that return values
          4. Asynchronous methods and the Windows Runtime APIs
        2. Using PLINQ to parallelize declarative data access
          1. Using PLINQ to improve performance while iterating through a collection
          2. Canceling a PLINQ query
        3. Synchronizing concurrent access to data
          1. Locking data
          2. Synchronization primitives for coordinating tasks
          3. Cancelling synchronization
          4. The concurrent collection classes
          5. Using a concurrent collection and a lock to implement thread-safe data access
        4. Summary
        5. Quick reference
      3. 25. Implementing the user interface for a Windows Store app
        1. What is a Windows Store app?
        2. Using the Blank App template to build a Windows Store app
          1. Implementing a scalable user interface
            1. Implementing a tabular layout by using a Grid control
            2. Adapting the layout by using the Visual State Manager
          2. Applying styles to a UI
        3. Summary
        4. Quick reference
      4. 26. Displaying and searching for data in a Windows Store app
        1. Implementing the Model-View-ViewModel pattern
          1.  
            1. Displaying data by using data binding
            2. Modifying data by using data binding
            3. Using data-binding with a ComboBox control
            4. Creating a ViewModel
            5. Adding commands to a ViewModel
          2. Windows 8.1 contracts
            1. Implementing the Search contract
            2. Navigating to a selected item
        2. Summary
        3. Quick reference
      5. 27. Accessing a remote database from a Windows Store app
        1.  
          1. Retrieving data from a database
            1. Creating an entity model
            2. Creating and using a REST web service
          2. Inserting, updating, and deleting data through a REST web service
            1. Reporting errors and updating the UI
        2. Summary
        3. Quick reference
    6. A. About the author
    7. Index
    8. About the Author
    9. Copyright

    Product information

    • Title: Microsoft Visual C# 2013 Step by Step
    • Author(s): John Sharp
    • Release date: November 2013
    • Publisher(s): Microsoft Press
    • ISBN: 9780735684959