Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
C# 7 and .NET Core Cookbook
C# 7 and .NET Core Cookbook

C# 7 and .NET Core Cookbook: Serverless programming, Microservices and more , Second Edition

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

C# 7 and .NET Core Cookbook

Classes and Generics

Classes form the building blocks of software development and are essential for building good code. In this chapter, we will be looking at classes and generics and why we need to use them. The recipes we will be covering are as follows:

  • Creating and implementing an abstract class
  • Creating and implementing an interface
  • Creating and using a generic class or method
  • Creating and using a generic interface

Introduction

As you probably know, classes are simply containers for related methods and properties to describe an object in your software. An object is an instance of a specific class and, sometimes, mimics real-world things. When thinking of a car, you might create a vehicle class that contains certain attributes (properties) that all vehicles contain, such as automatic or manual transmission, wheel count (not all vehicles have only four wheels), or fuel type.

When we create an instance of the vehicle class, we can create a car object, an SUV object, and so on. Here lies the power of classes, which is to describe the world around us and translate it into a programming language that a compiler can understand.

Creating and implementing an abstract class

Many developers have heard about abstract classes, but their implementation is a mystery. How can you as a developer identify an abstract class and decide when to use one? The definition is quite a simple one actually. Once you understand this fundamental definition of an abstract class, when and why to use one becomes obvious.

Imagine for a moment that you are developing an application that manages the animals in a cat sanctuary. The cat sanctuary rehabilitates lions, tigers, jaguars, leopards, cheetahs, pumas, and even domestic cats. The common noun that describes all these animals is the word cat. You can, therefore, safely assume that the abstraction of all these animals is a cat, and thus, this word identifies our abstract class. You would then create an abstract class called Cat.

However, you need to keep in mind that you will never ever create an instance of the...

Creating and implementing an interface

For many developers, interfaces are equally confusing and their purpose not clearly understood. Interfaces are actually quite easy to get to grips with once you understand the concept that defines an interface.

Interfaces act like verbs. So, for example, if we had to create two classes called Lion and Tiger that derive from the Cat abstract class, the interface would describe some sort of action. Lions and tigers can roar (but not purr). We can then create an interface called IRoarable. If we had to derive a class called Cheetah from our abstract class Cat, we would not be able to use the IRoarable interface, because cheetahs purr. We would need to create an IPurrable interface.

Getting ready

Creating an interface is very similar...

Creating and using a generic class or method

Generics is a very interesting way of writing code. Instead of specifying the data type of the elements in the code at design time, you can actually delay the specification of those elements until they are used in code. This basically means that your class or method can work with any data type.

Getting ready

We will start off by writing a generic class that can take any data type as a parameter in its constructor and do something with it.

How to do it...

  1. Declaring a generic class is actually very easy. All that we need to do is create the class with the generic type parameter...

Creating and using a generic interface

Generic interfaces work in much the same way as the previous examples in generics. Let's assume that we want to find the properties of certain classes in our code, but we can't be sure how many classes we will need to inspect. A generic interface could come in very handy here.

Getting ready

We need to inspect several classes for their properties. To do this, we will create a generic interface that will return a list of all the properties found for a class as a list of strings.

How to do it...

Let's take a look at the following implementation of the generic interface...

Left arrow icon Right arrow icon

Key benefits

  • Easy-to-follow recipes to get you up-and-running with the new features of C# 7 and .NET Core 1.1
  • Practical solutions to assist you with microservices and serverless computing in C#
  • Explore the new Visual Studio environment and write more secure code in it

Description

C# has recently been open-sourced and C# 7 comes with a host of new features for building powerful, cross-platform applications. This book will be your solution to some common programming problems that you come across with C# and will also help you get started with .NET Core 1.1. Through a recipe-based approach, this book will help you overcome common programming challenges and get your applications ready to face the modern world. We start by running you through new features in C# 7, such as tuples, pattern matching, and so on, giving you hands-on experience with them. Moving forward, you will work with generics and the OOP features in C#. You will then move on to more advanced topics, such as reactive extensions, Regex, code analyzers, and asynchronous programming. This book will also cover new, cross-platform .NET Core 1.1 features and teach you how to utilize .NET Core on macOS. Then, we will explore microservices as well as serverless computing and how these benefit modern developers. Finally, you will learn what you can do with Visual Studio 2017 to put mobile application development across multiple platforms within the reach of any developer.

Who is this book for?

The book will appeal to C# and .NET developers who have a basic familiarity with C# and the Visual Studio 2015 environment

What you will learn

  • Writing better and less code to achieve the same result as in previous versions of C#
  • Working with analyzers in Visual Studio
  • Working with files, streams, and serialization
  • Writing high-performant code in C# and understanding multi-threading
  • Demystifying the Rx library using Reactive extensions
  • Exploring .Net Core 1.1 and ASP.NET MVC
  • Securing your applications and learning new debugging techniques
  • Designing and building a microservice architecture
  • Using Azure and AWS for serverless computing with C#

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 25, 2017
Length: 628 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787289208
Vendor :
Microsoft
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 25, 2017
Length: 628 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787289208
Vendor :
Microsoft
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 134.97
C# 7 and .NET Core Cookbook
€41.99
C# 7.1 and .NET Core 2.0 ??? Modern Cross-Platform Development
€59.99
.NET Design Patterns
€32.99
Total 134.97 Stars icon
Banner background image

Table of Contents

16 Chapters
New Features in C# 7.0 Chevron down icon Chevron up icon
Classes and Generics Chevron down icon Chevron up icon
Object-Oriented Programming in C# Chevron down icon Chevron up icon
Code Analyzers in Visual Studio Chevron down icon Chevron up icon
Regular Expressions Chevron down icon Chevron up icon
Working with Files, Streams, and Serialization Chevron down icon Chevron up icon
Making Apps Responsive with Asynchronous Programming Chevron down icon Chevron up icon
High Performance Programming Using Parallel and Multithreading in C# Chevron down icon Chevron up icon
Composing Event-Based Programs Using Reactive Extensions Chevron down icon Chevron up icon
Exploring .NET Core 1.1 Chevron down icon Chevron up icon
ASP.NET Core on the MVC Framework Chevron down icon Chevron up icon
Choosing and Using a Source Control Strategy Chevron down icon Chevron up icon
Creating a Mobile Application in Visual Studio Chevron down icon Chevron up icon
Writing Secure Code and Debugging in Visual Studio Chevron down icon Chevron up icon
Creating Microservices on Azure Service Fabric Chevron down icon Chevron up icon
Azure and Serverless Computing Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3
(6 Ratings)
5 star 33.3%
4 star 0%
3 star 33.3%
2 star 33.3%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




wynix Jun 08, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Easy to understand, but very basic, definitely for learners.
Amazon Verified review Amazon
Thor Kornbrek Sep 19, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book provides content that can improve any developers game. There are a number of areas covered that I had been interested in but not had the time to really work with: Cordova, Asp.Net Core, and Azure Functions. This book delivers enough examples to get started in those areas and the vocabulary to further research where needed.I am sure you will find something to stretch your skills in this text. The power of C# and .Net Core is clearly demonstrated with screen-shots and step by step examples. I am going to keep a copy of this around as a reference as well.
Amazon Verified review Amazon
Bharat Nov 08, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Pages are not as good as expected
Amazon Verified review Amazon
Amazon Customer Oct 25, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Its easy to read and need less time to finish. Around 600 pages but less content. Page content is very less most of the pages have just dialog box or image only.
Amazon Verified review Amazon
Håvard Oct 21, 2018
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
The overall consept of this book is good. I have read a few chapters which gave me some valuable input. I skipped to the chapter about regular expressions, and started following the examples given in the text.That's when trouble started. The code for date validation and text sanitation given in the book will not work. The (not so) funny thing is that there is actually two lines for date validation which show a pattern that will work. But the portion saying something like "this is how it should look" will never work.If you download the source code, there it seems as if you will find working examples.Two stars, errors like this should have been found before this book hit the market. It seems as if the Packt books are rushed through the system, with not enough time for QA.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.