41,99 €
Quick fixes to your common C# programming problems, with a focus on C# 6.0
The book is aimed at developers who have basic familiarity with C# programming and will know the VS 2015 environment.
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
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.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 343
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: July 2016
Production reference: 1210716
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78646-730-0
www.packtpub.com
Author
Dirk Strauss
Reviewer
Fabio Claudio Ferracchiati
Commissioning Editor
Edward Gordon
Acquisition Editor
Nitin Dasan
Content Development Editor
Zeeyan Pinheiro
Technical Editor
Kunal Chaudhari
Copy Editor
Karuna Narayan
Project Coordinator
Izzat Contractor
Proofreader
Safis Editing
Indexer
Rekha Nair
Graphics
Jason Monteiro
Production Coordinator
Melwyn Dsa
Cover Work
Melwyn Dsa
Dirk Strauss is a software developer and Microsoft .NET MVP from South Africa with over 13 years of programming experience. He has extensive experience in SYSPRO Customization, an ERP system, with C# and web development as his main focus.
He works for Evolution Software, but in all fairness, he doesn't really like to call it working at all. According to him, when you're having fun and loving what you do with incredibly inspirational individuals, you will not work a day in your life.
Firstly, I would like to thank my mom for giving me the opportunities I had in life. Without your support, love, and sacrifice, I would not be where I am today. You made do with less so that I could have more. As I grow older, with kids of my own, I now realize the depth and breadth of your love and dearly appreciate it all.
I would also like to thank all of the educators at the Nelson Mandela Metropolitan University who are shaping the future IT professionals for an increasingly complex technological world. I specifically want to thank Professor Reinhardt A. Botha and Dr. Johan Van Niekerk. Their passion for information technology and their dedication to their students had a huge impact on me and made me the IT person I am today.
Throughout my career, I have met many people, had many colleagues, and dealt with more clients than I can probably remember. There is, however, a colleague and dear friend that has remained steadfast and resolute in his friendship, support, and mentorship. Vincent Van Zyl formed a big part of my early career and gave me a friendly nudge in the right direction when I was trying to find my way within a technology that was new to me. He was, and still is, a mentor and confidant in my professional life. He possesses a gentle spirit and a friendly nature that sets an example and truly makes the world a better place to live in. He loves his wife more than any man I have ever met and I am honored to know him, utterly humbled to call him a colleague, and incredibly blessed to have him as a friend.
Last but by no means least, I'd like to thank my wife and children. It would seem like such a cliché to thank you for putting up with me during the weekends and evenings that I spent working on this book, as this is a common theme that almost all authors thank their families for. The reality is that you all went above and beyond what was needed for me to complete this book. You guys expressed a profound understanding of what this project meant to me, which was so evident in the way your actions and sacrifices made a difference. Adele, you are my wingman, my comrade of can-do, and my rock throughout some grueling times. From the little things you did, such as supplying copious amounts of coffee in the cold evenings with an accuracy that made me wonder if you could read my mind, to the more important things, such as being mommy and daddy to our kids, fills me with an appreciation and gratitude that I will probably never be able to repay. I saw it all, I appreciate it all, and I love you all the more for it.
To my daughter Irénéé (pops) and my son Tristan (squeak), while you are still too young to read this now, you will be able to one day. I want to thank you for making do with a little less daddy time and for being patient and understanding when daddy could not play. You kids make me a better man and inspire me to face challenges in all aspects of my life with a determination and resolve I see in your eyes every day. You teach me more about life and all that is good by just being who you are. Your dreams are my dreams come true and there is nothing in this existence of ours that can separate me from the love I have for you. I therefore dedicate this book to Adele, Irénéé, and Tristan.
Fabio Claudio Ferracchiati is a senior consultant and a senior analyst/developer using Microsoft technologies. He works for Blu Arancio (www.bluarancio.com). He is a Microsoft Certified Solution Developer for .NET, Microsoft Certified Application Developer for .NET, and Microsoft Certified Professional. He is also a prolific author and technical reviewer. Over the last ten years, he's written articles for Italian and international magazines and coauthored more than 10 books on a variety of computer topics.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Visual Studio 2015 brings a lot to the developer's toolset when it comes to creating world-class applications across a variety of platforms. The new language features in C# 6.0 provide developers with easier ways to perform familiar tasks. This book will show you the beauty of C#, which when combined with the power of Visual Studio, makes you a very formidable developer capable of meeting a variety of programming challenges head on.
Many of the chapters in this book will provide you with just enough to jumpstart your understanding of the topics discussed. Irrespective of your skill level, when it comes to programming with C#, this book provides something for everyone.
Chapter 1, New Features in C# 6.0, introduces you to the new features available in C# 6.0.
Chapter 2, Classes and Generics, covers classes and generics, which form the building blocks of modern day applications. You will learn what they are and how to use them more effectively.
Chapter 3, Object-Oriented Programming in C#, covers OOP, which is why we do what we do in the way we do it. We will discuss the fundamentals when it comes to this concept.
Chapter 4, Composing Event-Based Programs Using Reactive Extensions, helps you make your applications more responsive using Rx and leveraging the power of providing real-time data.
Chapter 5, Create Microservices on Azure Service Fabric, shows how you can break away from the traditional approach to developing applications. Instead of one single monolithic application, microservices break an application up into smaller bits that can function on their own.
Chapter 6, Making Apps Responsive with Asynchronous Programming, covers using asynchronous programming to never let your application lock up because it is waiting for a long running task to complete.
Chapter 7, High Performance Programming Using Parallel and Multithreading in C#, demonstrates how you can make good use of the performance provided by today's multicore CPUs.
Chapter 8, Code Contracts, deals with writing robust code that will validate the correctness of data being passed to a method. We will also cover code contracts, which allow developers to write better code.
Chapter 9, Regular Expressions, covers regex, which is a technology that is baked into the .NET Framework and is often overlooked in most books. Understanding it better will go a long way toward adding value to your skillset.
Chapter 10, Choosing and Using a Source Control Strategy, delves into the different strategies that different developers in different situations require when it comes to using source control.
Chapter 11, Creating a Mobile Application in Visual Studio, discusses what you can do with Visual Studio, which has made it possible to make developing mobile applications across multiple platforms within reach for practically any developer.
Chapter 12, Writing Secure Code and Debugging in Visual Studio, emphasizes how being able to write more secure code will set your application apart from others. Being able to debug like a boss will set you apart from the rest.
Chapter 13, Creating a Web Application in Azure, demonstrates just how easy it is to create a web application in Azure.
To complete the code samples in this book, you will need a copy of Visual Studio 2015 or later. Most other required components can be installed via NuGet.
This book is aimed at developers who have basic familiarity with C# programming and know the VS 2015 environment.
In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).
To give clear instructions on how to complete a recipe, we use these sections as follows:
This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.
This section contains the steps required to follow the recipe.
This section usually consists of a detailed explanation of what happened in the previous section.
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
This section provides helpful links to other useful information for the recipe.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Add a class called CSharpSix. Add a property to this class called FavoriteFeature."
A block of code is set as follows:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Start Visual Studio 2015 and click on the File menu. Then, click on New and then select Project."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/CSharp-Programming-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/CSharpProgrammingCookbook_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
In this chapter, we will cover the following recipes with regard to the new features of C# 6.0:
C# as a programming language first appeared in 2000. Its development team is led by the prominent Danish software engineer Anders Hejlsberg. He is the lead architect of C# and core developer of TypeScript. The C# programming language is simple to use, and this book will deal with C# 6.0, which was released on 20 July, 2015.
Knowing what new language features are available in C# 6.0 will not only make you a more effective developer, but will also allow you to implement the latest and best practices in the software that you create. A little-known fact is that C# was actually called C-like Object Oriented Language (Cool) before its release at Microsoft's Professional Developers Conference in July 2000, but was changed to C# at the time of its release.
The name might have changed, but C# remains a very cool language to learn and use. This chapter will take you through the new features of C# 6.0 and illustrate how to effectively use these features in you daily programming tasks.
The Visual Studio project that you will create will be used to add the classes that contain the code samples in each recipe of this book. The project will be a simple console application that will call into static classes that do the work of illustrating the recipe code and outputting the results (if any) to the console window.
To step through the recipes in this book, you will need a copy of Visual Studio 2015. If you do not have a copy of Visual Studio 2015, you can download a free copy of Visual Studio 2015 Community from https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx.
You can also compare editions of Visual Studio 2015 by navigating to https://www.visualstudio.com/en-us/products/compare-visual-studio-2015-products-vs.aspx.
After you have downloaded and installed Visual Studio 2015, create a new console application that will contain the recipes illustrated in this book.
You will notice that the selected framework is .NET Framework 4.6.1, which is selected by default. Leave this framework selected when creating your project.
This console application will form the base of the recipes in this book. Each recipe can be individually added to this console application. A recipe, therefore, can function on its own without the need to create a previous recipe. You can also easily separate any custom code you might want to add and experiment with. It is also recommended that you play around with the code by adding classes of your own.