C# Programming Cookbook

Book description

Quick fixes to your common C# programming problems, with a focus on C# 6.0

About This Book

  • Unique recipes for C#, that places it in its real-world context.
  • You will be able to get yourself out of any coding-corner youve backed yourself into.
  • All code samples available through GitHub to bring C#.
  • In line with modern development workflows, written to the latest specification of C# 6.0.

Who This Book Is For

The book is aimed at developers who have basic familiarity with C# programming and will know the VS 2015 environment.

What You Will Learn

  • Write better and less code to achieve the same result as in previous versions of C#.
  • Generate tests from the Code Contracts for mission critical methods.
  • Integrate code in Visual Studio with GitHub.
  • Create a web application in Azure.
  • Design and build a microservice architecture
  • Demystify the Rx library using Reactive extensions
  • Write high performing codes in C# and understanding multi-threading.
  • Security and Debugging.
  • Implement Code Contracts on code in Visual Studio.

In Detail

During your application development workflow, there is always a moment when you need to get out of a tight spot. Through a recipe-based approach, this book will help you overcome common programming problems and get your applications ready to face the modern world.

We start with C# 6, giving you hands-on experience with the new language features. Next, we work through the tasks that you perform on a daily basis such as working with strings, generics, and lots more. Gradually, we move on to more advanced topics such as the concept of object-oriented programming, asynchronous programming, reactive extensions, and code contracts.

You will learn responsive high performance programming in C# and how to create applications with Azure. Next, we will review the choices available when choosing a source control solution. At the end of the book, we will show you how to create secure and robust code, and will help you ramp up your skills when using the new version of C# 6 and Visual Studio

Style and Approach

Unique recipe-based guide that will help you gain a solid understanding of the new concepts in C# 6 and Visual Studio Enterprise 2015 in a concise and technically correct manner.

Table of contents

  1. C# Programming Cookbook
    1. Table of Contents
    2. C# Programming Cookbook
    3. Credits
    4. About the Author
    5. Acknowledgements
    6. About the Reviewer
    7. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why Subscribe?
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Sections
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    9. 1. New Features in C# 6.0
      1. Introduction
      2. Creating your Visual Studio project
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. String interpolation
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Null-conditional operator
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Initializers for auto-implemented properties and getter-only auto properties
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Index initializers
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. The nameof expressions
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Expression-bodied functions and properties
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Using static
        1. Getting ready
        2. How to do it…
        3. How it works…
      10. Exception filters
        1. Getting ready
        2. How to do it…
        3. How it works…
      11. Using await operator in catch and finally blocks
        1. Getting ready
        2. How to do it…
        3. How it works…
    10. 2. Classes and Generics
      1. Introduction
      2. Creating and implementing an abstract class
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Creating and implementing an interface
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Creating and using a generic class or method
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Creating and using a generic interface
        1. Getting ready
        2. How to do it…
        3. How it works…
    11. 3. Object-Oriented Programming in C#
      1. Introduction
      2. Using inheritance in C#
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Using abstraction
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Leveraging encapsulation
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Implementing polymorphism
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Single responsibility principle
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Open/closed principle
        1. Getting ready
        2. How to do it…
        3. How it works…
    12. 4. Composing Event-Based Programs Using Reactive Extensions
      1. Introduction
      2. Installing Rx
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Events versus observables
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Using LINQ to perform queries
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Using schedulers in Rx
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Debugging lambda expressions
        1. Getting ready
        2. How to do it…
        3. How it works…
    13. 5. Create Microservices on Azure Service Fabric
      1. Introduction
      2. Downloading and installing Service Fabric
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Creating a Service Fabric application with a stateless actor service
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Using Service Fabric Explorer
        1. Getting ready
        2. How to do it…
        3. How it works…
    14. 6. Making Apps Responsive with Asynchronous Programming
      1. Introduction
      2. Return types of asynchronous functions
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Handling tasks in asynchronous programming
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Exception handling in asynchronous programming
        1. Getting ready
        2. How to do it…
        3. How it works…
    15. 7. High Performance Programming Using Parallel and Multithreading in C#
      1. Introduction
      2. Creating and aborting a low-priority background thread
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Increasing maximum thread pool size
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Creating multiple threads
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Locking one thread until the contended resources are available
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Invoking parallel calls to methods using Parallel.Invoke
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Using a parallel foreach loop to run multiple threads
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Cancelling a parallel foreach loop
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Catching errors in parallel foreach loops
        1. Getting ready
        2. How to do it…
        3. How it works…
      10. Debugging multiple threads
        1. Getting ready
        2. How to do it…
        3. How it works…
    16. 8. Code Contracts
      1. Introduction
      2. Downloading, installing, and integrating code contracts into Visual Studio
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Creating code contract preconditions
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Creating code contract postconditions
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Creating code contract invariant
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Creating code contract Assert and Assume methods
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Creating code contract ForAll method
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Creating code contract ValueAtReturn method
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Creating code contract Result method
        1. How to do it…
        2. How it works…
      10. Using code contracts on abstract classes
        1. Getting ready
        2. How to do it…
        3. How it works…
      11. Using contract abbreviator methods
        1. Getting ready
        2. How to do it…
        3. How it works…
      12. Creating tests using IntelliTest
        1. Getting ready
        2. How to do it…
        3. How it works…
      13. Using code contracts in extension methods
        1. Getting ready
        2. How to do it…
        3. How it works…
    17. 9. Regular Expressions
      1. Introduction
      2. Getting started with regex
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Matching a valid date
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Sanitizing input
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Dynamic regex matching
        1. Getting ready
        2. How to do it…
        3. How it works…
    18. 10. Choosing and Using a Source Control Strategy
      1. Introduction
      2. Setting up Visual Studio account management and determining which source control solution is best for you
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Setting up Visual Studio GitHub integration, checking in code for the first time, and checking in changes
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Working as a team using GitHub, and handling and resolving conflicts in code
        1. Getting ready
        2. How to do it...
        3. How it works...
    19. 11. Creating a Mobile Application in Visual Studio
      1. Introduction
      2. Installing Xamarin and other required components
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Creating an Android Visual Studio project using Apache Cordova
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Creating an iOS application using Xamarin Forms
        1. Getting ready
        2. How to do it…
        3. How it works…
    20. 12. Writing Secure Code and Debugging in Visual Studio
      1. Introduction
      2. Encrypting and storing passwords correctly
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Using SecureString in code
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Securing sensitive parts of App.config/web.config
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Preventing SQL injection attacks
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Using Diagnostic Tools and Historical Debugging
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Setting conditional breakpoints
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Using PerfTips to identify bottlenecks in code
        1. Getting ready
        2. How to do it…
        3. How it works…
    21. 13. Creating a Web Application in Azure
      1. Introduction
      2. Creating a database in Azure for testing
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Creating a web application and hosting on Azure
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Using virtual machines on Azure
        1. Getting ready
        2. How to do it…
        3. How it works…
    22. Index

Product information

  • Title: C# Programming Cookbook
  • Author(s): Dirk Strauss
  • Release date: July 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781786467300