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
Arrow up icon
GO TO TOP
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development

You're reading from   C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher Packt
ISBN-13 9781788478120
Length 818 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Mark J. Price Mark J. Price
Author Profile Icon Mark J. Price
Mark J. Price
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

1. Hello, C#! Welcome, .NET! FREE CHAPTER 2. Speaking C# 3. Controlling Flow and Converting Types 4. Writing, Debugging, and Testing Functions 5. Building Your Own Types with Object-Oriented Programming 6. Implementing Interfaces and Inheriting Classes 7. Understanding and Packaging .NET Types 8. Working with Common .NET Types 9. Working with Files, Streams, and Serialization 10. Protecting Your Data and Applications 11. Working with Databases Using Entity Framework Core 12. Querying and Manipulating Data Using LINQ 13. Improving Performance and Scalability Using Multitasking 14. Practical Applications of C# and .NET 15. Building Websites Using ASP.NET Core Razor Pages 16. Building Websites Using the Model-View-Controller Pattern 17. Building Websites Using a Content Management System 18. Building and Consuming Web Services 19. Building Intelligent Apps Using Machine Learning 20. Building Windows Desktop Apps 21. Building Cross-Platform Mobile Apps Using Xamarin.Forms

Looking for help

This section is all about how to find quality information about programming on the web.

Reading Microsoft documentation

The definitive resource for getting help with Microsoft developer tools and platforms used to be Microsoft Developer Network (MSDN). Now, it is Microsoft Docs, and you can find it at the following link: https://docs.microsoft.com/.

Getting help for the dotnet tool

At the command line, you can ask the dotnet tool for help about its commands.

  1. To open the official documentation in a browser window for the dotnet new command, enter the following at the command line or in Visual Studio Code Terminal:
    dotnet help new
  2. To get help output at the command line, use the -h or --help flag, as shown in the following command:
    dotnet new console -h
  3. You will see the following partial output:
    Console Application (C#)
    Author: Microsoft
    Description: A project for creating a command-line application that can run on .NET Core on Windows, Linux and macOS
    Options:                                                     
      --langVersion  Sets langVersion in the created project file
                     text - Optional
      --no-restore   If specified, skips the automatic restore of the project on create.
                     bool - Optional
                     Default: false / (*) true
    * Indicates the value used if the switch is provided without a value.

Getting definitions of types and their members

One of the most useful keyboard shortcuts in Visual Studio Code is F12 to Go To Definition. This will show what the public definition of the type or member looks like by reading the metadata in the compiled assembly. Some tools like ILSpy .NET Decompiler will even reverse-engineer from the metadata and IL code back into C# for you.

  1. In Visual Studio Code, open the HelloCS folder.
  2. In Program.cs, inside the Main method, enter the following statement to declare an integer variable named z:
    int z;
  1. Click inside int and then press F12, or right-click and choose Go To Definition. In the new code window that appears, you can see how the int data type is defined, as shown in the following screenshot:

    You can see that int:

    • Is defined using the struct keyword.
    • Is in the System.Runtime assembly.
    • Is in the System namespace.
    • Is named Int32.
    • Is therefore an alias for the System.Int32 type.
    • Implements interfaces such as IComparable.
    • Has constant values for its maximum and minimum values.
    • Has methods like Parse.

      Good Practice: When you try to use Go To Definition you will sometimes see an error saying, No definition found. This is because the C# extension does not know about the current project. Navigate to View | Command Palette, enter and select OmniSharp: Select Project, and then select the correct project that you want to work with.

      Right now, the Go To Definition feature is not that useful to you because you do not yet know what these terms mean.

      By the end of the first part of this book, which teaches you about C#, you will know enough for this feature to become very handy.

  1. In the code editor window, scroll down to find the Parse method with a single string parameter starting on line 86, as shown in the following screenshot:

In the comment, you will see that Microsoft has documented what exceptions might occur if you call this method, including ArgumentNullException, FormatException, and OverflowException. Now, we know that we need to wrap a call to this method in a try statement and which exceptions to catch.

Hopefully, you are getting impatient to learn what all this means!

Be patient for a little longer. You are almost at the end of this chapter, and in the next chapter you will dive into the details of the C# language. But first, let's see where else you can look for help.

Looking for answers on Stack Overflow

Stack Overflow is the most popular third-party website for getting answers to difficult programming questions. It's so popular that search engines such as DuckDuckGo have a special way to write a query to search the site.

  1. Start your favorite web browser.
  1. Navigate to DuckDuckGo.com, enter the following query, and note the search results, which are also shown in the following screenshot:
    !so securestring

Searching for answers using Google

You can search Google with advanced search options to increase the likelihood of finding what you need.

  1. Navigate to Google.
  2. Search for information about garbage collection using a simple Google query, and note that you will probably see a Wikipedia definition of garbage collection in computer science, and then a list of garbage collection services in your local area, as shown in the following screenshot:
  1. Improve the search by restricting it to a useful site such as Stack Overflow, and by removing languages that we might not care about such as C++, Rust, and Python, or by adding C# and .NET explicitly, as shown in the following search query:
    garbage collection site:stackoverflow.com +C# -Java

Subscribing to the official .NET blog

To keep up to date with .NET, an excellent blog to subscribe to is the official .NET Blog written by the .NET engineering teams, and you can find it at the following link: https://blogs.msdn.microsoft.com/dotnet/

You have been reading a chapter from
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development - Fourth Edition
Published in: Oct 2019
Publisher: Packt
ISBN-13: 9781788478120
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image