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
Conferences
Free Learning
Arrow right icon
Mastering Visual Studio 2017
Mastering Visual Studio 2017

Mastering Visual Studio 2017: Build windows apps using WPF and UWP, accelerate cloud development with Azure, explore NuGet, and more

eBook
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.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

Mastering Visual Studio 2017

What is New in C# 7.0?

C# is a simple, modern, object-oriented programming language with support for component-oriented programming. It constructs robust applications using automatic garbage collection of unused objects, proper exception handling, and type-safe design.

Along with Visual Studio 2017, Microsoft introduces the next version of C#, that is, C# 7.0, which provides several changes and new features for developers to build rapid and robust applications without spending more time on code.

In this chapter, we will learn about the following new features introduced in C# 7.0, guided through the code:

  • Local functions or nested functions
  • Literal improvements in C# 7.0
  • The new digit separators
  • Getting to know about pattern matching
  • The ref returns and locals
  • New changes to tuples
  • Changes to the throw expression
  • Changes to Expression-bodied members
  • New changes to the out variables...

Local functions or nested functions

C# 7.0, which comes with Visual Studio 2017, allows you to write local functions or nested functions. The local function provides you with the ability to declare methods/functions inside an already defined methods body. It has the same capability as normal methods, but it will be scoped to the method block where they are declared.

In earlier versions of C#, we needed to write the method bodies separately and then we needed to call one method from the other. Here is the old way to write a method called by another method:

     public static Person GetBloggerDetails() 
     { 
       return new Person 
       { 
         FirstName = "Kunal", 
         LastName = "Chowdhury", 
         Blogs = GetBlogs() 
       }; 
     } 
 
     private static List<string> GetBlogs() 
     { 
       return new List<string> { &quot...

Literal improvements in C# 7.0

There were two types of literals supported in C# prior to C# 7.0. They are decimal literals and hexadecimal literals. For example, 490 is a decimal literal, whereas 0x50A or 0X50A is a hexadecimal literal, equivalent to the decimal value 490. Please note that the prefixes 0x and 0X define the same thing.

Here's an example for you to easily understand how a hexadecimal literal is used in C#:

 
    class Program 
    { 
      static void Main(string[] args) 
      { 
        double height = 490; 
        double width = 1290; 
 
        double heightInHex = 0x1EA; // equivalent to decimal 490 
        double widthInHex = 0x50A; // equivalent to decimal 1290 
 
        Console.WriteLine("Height: " + heightInHex + " Width: " + widthInHex); 
      } 
    } 

Along with C# 7.0, Microsoft added more support to literals, and they...

The new digit separators

Digit separator is a new feature in C# 7.0. You can use _ (underscore) inside numeric literals as a digit separator. The purpose of it is none other than improving the readability of the value in code.

You can put a digit separator (_) wherever you want between digits. You can have multiple underscores (____) too. They will have no effect on the value. This is shown in the following code snippet:

    var decimalValue1 = 1_50_000; // better than 150000 
    var decimalValue2 = 25_91_50_000; // better than 259150000 
 
    // you can use multiple underscores too 
    var decimalValue3 = 25_91__50___000; // better than 259150000 

You can also add digit separators to a binary literal and/or hexadecimal literals:

    var binaryValue = 0b1010_1011_1100_1101_1110_1111; 
    var hexadecimalValue = 0xAB_C_0_D_EF_578; 
 

Please note that the following conventions...

Getting to know about pattern matching

Pattern matching is a new notion introduced in C# 7.0, which adds some power to the existing operators and statements. You can perform pattern matching on any data type and from that statement you can extract the value of that data type. There are two different types of pattern matching in C# 7.0:

  • The Is expression with pattern matching
  • Switch statements with pattern matching

The Is expression with pattern matching

In this type of pattern matching, it introduces a new pattern variable out of the expression, allowing you to extract the value of the type. It is similar to the out variable, but with a limited scope to the surroundings.

Let's look at an example. In the old method,...

The ref returns and locals

Since C# 1.0, the language has supported passing parameters to a method by reference using the ref, but there exists no mechanism to return a safe reference to stack or heap memory locations.

In C# 7.0, Microsoft has provided the option for developers to return values by reference and store them in local variables as a reference pointer.

Before going into an example of return by reference, let us first look at an example of how the return by value works with a pass by reference parameter. In the following example, the GetAsValue method accepts a third parameter of type integer as a reference, and returns a value to the callee, which gets stored in the local variable name:

    public static void DemoReturnAsValue() 
    { 
      var count = 0; 
      var index = 0; 
      string[] names = { "Kunal", "Manika", "Dwijen" };...

New changes to tuples

A tuple is a finite ordered list of elements. In C#, it's not a new thing, having been available since .NET Framework 4.0. It is useful when you want to return multiple values from a method without creating a separate class or collection to hold the data. Tuples are declared in the manner, Tuple<T1, T2, T3, ...> and are available under the System namespace.

By default, a tuple can hold up to eight value types, but you can extend it by adding the reference of System.Runtime.

Although this is useful when returning multiple values, you need to create an allocation for the System.Tuple<...> object. The following example demonstrates how to return multiple values using a tuple:

   public static Tuple<string, string> GetAuthor() 
   { 
     return new Tuple<string, string>("Kunal Chowdhury", 
                             ...

Changes to the throw expression

The earlier versions of C# had some limitations on throwing exceptions from certain places, which caused developers to write more code to validate and raise exceptions. In C# 7.0, those limitations have been removed to reduce the overload.

The Null Coalescing operator now allows you to throw an exception in the middle of the expression without explicitly checking for null:

    m_designation = designation ?? 
          throw new ArgumentNullException(designation); 

It is now possible to throw an exception from the Conditional operator too:

    m_department = department == null ?  
           throw new ArgumentNullException(department) :  
           department; 

C# 7.0 also allows you to throw an exception from expression-bodied member, as shown in the following code snippet:

    public void SetSalary(double salary) =>  
           throw new...

Changes to the expression-bodied members

In C# 6.0, Microsoft introduced the expression-bodied methods and properties, but these had a few limitations, which didn't allow us to use them in the constructors, destructors, and getters/setters of properties.

With C# 7.0, these limitations are no more, and you can now write them for single-liner constructors and destructors, as well as the getter and setter of a property. Here's how you can use them:

    public class Person 
    { 
      private string m_name; 
 
      // constructor 
      public Person() => Console.WriteLine("Constructor called"); 
 
      // destructor 
      ~Person() => Console.WriteLine("Destructor called"); 
 
      // getter/setter properties 
      public string Name 
      { 
        get => m_name; 
        set => m_name = value; 
      } 
    } 

When you run the...

New changes with the out variables

Currently in C#, we need to first declare a variable before we pass it as an out parameter to a method. You can use a var while declaration if you initialize them in the same line, but when you don't want to initialize explicitly, you must declare them, specifying the full type:

    // predeclaration of 'out' variable was mandatory 
    int result; // or, var result = 0; 
    string value = "125"; 
 
    int.TryParse(value, out result); 
 
    Console.WriteLine("The result is: " + result); 

In C# 7.0, the out variables can be declared right at the point where they are passed as an out parameter to a method. You can now directly write int.TryParse(value, out int result); and get the value of the out parameter, to use it in the scope of the enclosing block:

    static void Main(string[] args) 
    { 
      string...

Getting to know about deconstruction syntax

Deconstruction is a syntax to split a value into multiple parts and store those parts individually into new variables. For example, tuples that return multiple values. Let us take the following method as an example, which returns a tuple of two string variables, Title and Author (see the New changes to tuples section):

    public (string Title, string Author) GetBookDetails() 
    { 
       return (Title: "Mastering Visual Studio 2017",
Author: "Kunal Chowdhury"); }

Now, when you call the method GetBookDetails(), it will return a tuple. You can access its elements by calling the element name, as follows:

  var bookDetails = GetBookDetails(); // returns Tuple 
  Console.WriteLine("Title  : " + bookDetails.Title); 
  Console.WriteLine("Author : " + bookDetails.Author); 

In a...

Uses of the generalized async return types

Prior to C# 7.0, async methods had to return either void, Task, or Task<T>. As Task is a reference type, returning such an object from async methods can impact performance because it allocates an object into memory even though it returns a cached object or runs asynchronously.

To overcome this, C# 7.0 introduces the ValueTask type, which is set to prevent the allocation of a Task<T> object when the result of the async operation is already available. Using it, the async methods can return types other than Task, Task<T>, and void:

  public async ValueTask<long> GetValue() 
  { 
    return await Task.Run<long>(() => 5000); 
  } 

If you receive an error accessing ValueTask in C# 7.0, you must explicitly reference System.Threading.Tasks.Extensions from the NuGet package library. To install the package, either...

Summary

In this chapter, we have learned about the new features introduced in C# 7.0, along with the release of Visual Studio 2017. We have also demonstrated each of them with examples/code.

At a glance, we have learned about local or nested functions, literal improvements, the new digit separators, pattern matching, ref returns and locals, changes in tuples, changes to the throw expression, and expression-bodied members. We also learned about the new changes to the out variables, deconstruction syntax, and the uses of generalized async return types.

As we have become familiar with the features of C# 7.0, let's move on to the next chapter, where we will learn about building applications for Windows using Windows Presentation Foundation. We will also learn how to design a XAML UI, do data bindings, and much more.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Focus on coding with the new, improved, and powerful tools of VS 2017
  • Master improved debugging and unit testing support capabilities
  • Accelerate cloud development with the built-in Azure tools

Description

Visual Studio 2017 is the all-new IDE released by Microsoft for developers, targeting Microsoft and other platforms to build stunning Windows and web apps. Learning how to effectively use this technology can enhance your productivity while simplifying your most common tasks, allowing you more time to focus on your project. With this book, you will learn not only what VS2017 offers, but also what it takes to put it to work for your projects. Visual Studio 2017 is packed with improvements that increase productivity, and this book will get you started with the new features introduced in Visual Studio 2017 IDE and C# 7.0. Next, you will learn to use XAML tools to build classic WPF apps, and UWP tools to build apps targeting Windows 10. Later, you will learn about .NET Core and then explore NuGet, the package manager for the Microsoft development platform. Then, you will familiarize yourself with the debugging and live unit testing techniques that comes with the IDE. Finally, you'll adapt Microsoft's implementation of cloud computing with Azure, and the Visual Studio integration with Source Control repositories.

Who is this book for?

.NET Developers who would like to master the new features of VS 2017, and would like to delve into newer areas such as cloud computing, would benefit from this book. Basic knowledge of previous versions of Visual Studio is assumed.

What you will learn

  • Learn what s new in the Visual Studio 2017 IDE, C# 7.0, and how it will help developers to improve their productivity
  • Learn the workloads and components of the new installation wizard and how to use the online and offline installer
  • Build stunning Windows apps using Windows Presentation Foundation (WPF) and Universal Windows Platform (UWP) tools
  • Get familiar with .NET Core and learn how to build apps targeting this new framework
  • Explore everything about NuGet packages
  • Debug and test your applications using Visual Studio 2017
  • Accelerate cloud development with Microsoft Azure
  • Integrate Visual Studio with most popular source control repositories, such as TFS and GitHub

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 27, 2017
Length: 466 pages
Edition : 1st
Language : English
ISBN-13 : 9781787280656
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 : Jul 27, 2017
Length: 466 pages
Edition : 1st
Language : English
ISBN-13 : 9781787280656
Vendor :
Microsoft
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 189.97
C# 7 and .NET Core Cookbook
$54.99
Mastering Visual Studio 2017
$54.99
C# 7.1 and .NET Core 2.0 ??? Modern Cross-Platform Development
$79.99
Total $ 189.97 Stars icon
Banner background image

Table of Contents

10 Chapters
What is New in Visual Studio 2017 IDE? Chevron down icon Chevron up icon
What is New in C# 7.0? Chevron down icon Chevron up icon
Building Applications for Windows Using XAML Tools Chevron down icon Chevron up icon
Building Applications for Windows 10 Using UWP Tools Chevron down icon Chevron up icon
Building Applications with .NET Core Chevron down icon Chevron up icon
Managing NuGet Packages Chevron down icon Chevron up icon
Debugging Applications with Visual Studio 2017 Chevron down icon Chevron up icon
Live Unit Testing with Visual Studio 2017 Chevron down icon Chevron up icon
Accelerate Cloud Development with Microsoft Azure Chevron down icon Chevron up icon
Working with Source Controls Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9
(7 Ratings)
5 star 28.6%
4 star 0%
3 star 28.6%
2 star 14.3%
1 star 28.6%
Filter icon Filter
Top Reviews

Filter reviews by




JP Georgia Sep 06, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A great, detailed tutorial about the premier software development tool. The book covers what every developer needs to know about Visual Studio. If the cost of VS daunts you, get the community version. It has all the features of Enterprise, including compile and distribute, and up to 5 developers can use it.
Amazon Verified review Amazon
Ernest C. Liedtke Nov 10, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book.
Amazon Verified review Amazon
John Cantrell Jan 19, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Still working through this text..
Amazon Verified review Amazon
Ben B Nov 20, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Very advanced for a beginner, have not got far in it!
Amazon Verified review Amazon
DHG Mar 08, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I get the book and it requires that you download material from their website. Except the website requires that you register. Except that the registration process is broken and you are supposed to email them. Except the email address returns your email with a notice that the address is not recognized.Sound like a load of crap?The books has some good stuff, but I am going to be loading a bunch of code by hand.Not nice.
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.