Search icon CANCEL
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

Arrow left icon
Profile Icon Kunal Chowdhury
Arrow right icon
€18.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (7 Ratings)
Paperback Jul 2017 466 pages 1st Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Kunal Chowdhury
Arrow right icon
€18.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (7 Ratings)
Paperback Jul 2017 466 pages 1st Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781787281905
Vendor :
Microsoft
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jul 27, 2017
Length: 466 pages
Edition : 1st
Language : English
ISBN-13 : 9781787281905
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 143.97
C# 7 and .NET Core Cookbook
€41.99
Mastering Visual Studio 2017
€41.99
C# 7.1 and .NET Core 2.0 ??? Modern Cross-Platform Development
€59.99
Total 143.97 Stars icon

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

Most Recent
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
Most Recent

Filter reviews by




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
Amazon Customer Feb 12, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Very hard to follow. Author jumps into confusing examples immediately. He reviews VS 2017 new features and does not prompt beginners to walk through the examples in VS. Maybe it is the difficult syntax and structure of XAML, but he throws terminology like namespaces and classes right away at the novice almost from the beginning. Best to go to Google and search on "WPF tutorial for beginners" rather than waste money on the Kindle for this publication.
Amazon Verified review Amazon
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
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
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.