Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development

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 , Fourth Edition

eBook
$9.99 $70.99
Paperback
$87.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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development

Chapter 02

Speaking C#

This chapter is all about the basics of the C# programming language. Over the course of this chapter, you'll learn how to write statements using the grammar of C#, as well as being introduced to some of the common vocabulary that you will use every day. In addition to this, by the end of the chapter you'll feel confident in knowing how to temporarily store and work with information in your computer's memory.

This chapter covers the following topics:

  • Introducing C#
  • Understanding the basics of C#
  • Working with variables
  • Working with null values
  • Further exploring console applications

Introducing C#

This part of the book is about the C# language—the grammar and vocabulary that you will use every day to write the source code for your applications.

Programming languages have many similarities to human languages, except that in programming languages, you can make up your own words, just like Dr. Seuss!

In a book written by Dr. Seuss in 1950, If I Ran the Zoo, he states this:

"And then, just to show them, I'll sail to Ka-Troo And Bring Back an It-Kutch, a Preep, and a Proo, A Nerkle, a Nerd, and a Seersucker, too!"

Understanding language versions and features

This part of the book covers the C# programming language and is written primarily for beginners, so it covers the fundamental topics that all developers need to know, from declaring variables to storing data to how to define your own custom data types.

Advanced and obscure topics like ref local variable reassignment and reference semantics with value types are not covered...

Understanding C# basics

To learn C#, you will need to create some simple applications. To avoid overloading you with too much information too soon, the chapters in the first part of this book will use the simplest type of application: a console application.

Let's start by looking at the basics of the grammar and vocabulary of C#. Throughout this chapter, you will create multiple console applications, with each one showing a feature of the C# language.

  1. If you've completed Chapter 1, Hello, C#! Welcome, .NET!, then you will already have a Code folder in your user folder. If not, then you'll need to create it.
  2. Create a subfolder named Chapter02, with a sub-subfolder named Basics.
  3. Start Visual Studio Code and open the Chapter02/Basics folder.
  4. In Visual Studio Code, navigate to View | Terminal, and enter the following command:
    dotnet new console
  5. In EXPLORER, click the Program.cs file, and then click on Yes to add the missing required assets...

Working with variables

All applications process data. Data comes in, data is processed, and then data goes out. Data usually comes into our program from files, databases, or user input, and it can be put temporarily into variables that will be stored in the memory of the running program. When the program ends, the data in memory is lost. Data is usually output to files and databases, or to the screen or a printer. When using variables, you should think about, firstly, how much space it takes in the memory, and, secondly, how fast it can be processed.

We control this by picking an appropriate type. You can think of simple common types such as int and double as being different-sized storage boxes, where a smaller box would take less memory but may not be as fast at being processed; for example, adding 16-bit numbers might not be processed as fast as adding 64-bit numbers on a 64-bit operating system. Some of these boxes may be stacked close by, and some may be thrown into a big...

Working with null values

You have now seen how to store primitive values like numbers in variables. But what if a variable does not yet have a value? How can we indicate that? C# has the concept of a null value, which can be used to indicate that a variable has not been set.

Making a value type nullable

By default, value types like int and DateTime must always have a value, hence their name. Sometimes, for example, when reading values stored in a database that allows empty, missing, or null values, it is convenient to allow a value type to be null, we call this a nullable value type.

You can enable this by adding a question mark as a suffix to the type when declaring a variable. Let's see an example.

  1. In the Chapter02 folder, create a new folder named NullHandling.
  2. Add the NullHandling folder to the Chapter02 workspace.
  3. Create a new Terminal window for the NullHandling project.
  4. Create a new console application project in the NullHandling folder.
  5. ...

Exploring console applications further

We have already created and used basic console applications, but we're now at a stage where we should delve into them more deeply.

Console applications are text-based and are run at the command line. They typically perform simple tasks that need to be scripted, such as compiling a file or encrypting a section of a configuration file.

Equally they can also have arguments passed to them to control their behavior. An example of this would be to create a new console app using the F# language with a specified name instead of using the name of the current folder, as shown in the following command line:

dotnet new console -lang "F#" -name "ExploringConsole"

Displaying output to the user

The two most common tasks that a console application performs are writing and reading data. We have already been using the WriteLine method to output, but if we didn't want a carriage return at the end of the lines, we could...

Practicing and exploring

Test your knowledge and understanding by answering some questions, get some hands-on practice, and explore the topics covered in this chapter with deeper research.

Exercise 2.1 – Test your knowledge

To get the best answer to some of these questions you will need to do your own research. I want you to "think outside the book" so I have deliberately not provided all the answers in the book.

I want to encourage you to get in the good habit of looking for help elsewhere, following the principle of "teach a person to fish."

What type would you choose for the following "numbers"?

  1. A person's telephone number.
  2. A person's height.
  3. A person's age.
  4. A person's salary.
  5. A book's ISBN.
  6. A book's price.
  7. A book's shipping weight.
  8. A country's population.
  9. The number of stars in the universe.
  1. The number of employees in each of the small...

Summary

In this chapter, you learned how to declare variables with a specified or an inferred type; we discussed some of the built-in types for numbers, text, and Booleans; we covered how to choose between number types; we covered nullability of types; we learned how to control the output formatting in console apps.

In the next chapter, you will learn about operators, branching, looping, and converting between types.

Left arrow icon Right arrow icon

Key benefits

  • Build modern, cross-platform applications with .NET Core 3.0
  • Get up to speed with C#, and up to date with all the latest features of C# 8.0
  • Start creating professional web applications with ASP.NET Core 3.0

Description

In C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development, Fourth Edition, expert teacher Mark J. Price gives you everything you need to start programming C# applications. This latest edition uses the popular Visual Studio Code editor to work across all major operating systems. It is fully updated and expanded with new chapters on Content Management Systems (CMS) and machine learning with ML.NET. The book covers all the topics you need. Part 1 teaches the fundamentals of C#, including object-oriented programming, and new C# 8.0 features such as nullable reference types, simplified switch pattern matching, and default interface methods. Part 2 covers the .NET Standard APIs, such as managing and querying data, monitoring and improving performance, working with the filesystem, async streams, serialization, and encryption. Part 3 provides examples of cross-platform applications you can build and deploy, such as web apps using ASP.NET Core or mobile apps using Xamarin.Forms. The book introduces three technologies for building Windows desktop applications including Windows Forms, Windows Presentation Foundation (WPF), and Universal Windows Platform (UWP) apps, as well as web applications, web services, and mobile apps.

Who is this book for?

Readers with some prior programming experience or with a science, technology, engineering, or mathematics (STEM) background, who want to gain a solid foundation with C# 8.0 and .NET Core 3.0.

What you will learn

  • Build cross-platform applications for Windows, macOS, Linux, iOS, and Android
  • Explore application development with C# 8.0 and .NET Core 3.0
  • Explore ASP.NET Core 3.0 and create professional web applications
  • Learn object-oriented programming and C# multitasking
  • Query and manipulate data using LINQ
  • Use Entity Framework Core and work with relational databases
  • Discover Windows app development using the Universal Windows Platform and XAML
  • Build mobile applications for iOS and Android using Xamarin.Forms

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 31, 2019
Length: 818 pages
Edition : 4th
Language : English
ISBN-13 : 9781788471572
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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 31, 2019
Length: 818 pages
Edition : 4th
Language : English
ISBN-13 : 9781788471572
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 $ 170.97
Hands-On Network Programming with C# and .NET Core
$43.99
Hands-On Design Patterns with C# and .NET Core
$38.99
C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development
$87.99
Total $ 170.97 Stars icon
Banner background image

Table of Contents

21 Chapters
Hello, C#! Welcome, .NET! Chevron down icon Chevron up icon
Speaking C# Chevron down icon Chevron up icon
Controlling Flow and Converting Types Chevron down icon Chevron up icon
Writing, Debugging, and Testing Functions Chevron down icon Chevron up icon
Building Your Own Types with Object-Oriented Programming Chevron down icon Chevron up icon
Implementing Interfaces and Inheriting Classes Chevron down icon Chevron up icon
Understanding and Packaging .NET Types Chevron down icon Chevron up icon
Working with Common .NET Types Chevron down icon Chevron up icon
Working with Files, Streams, and Serialization Chevron down icon Chevron up icon
Protecting Your Data and Applications Chevron down icon Chevron up icon
Working with Databases Using Entity Framework Core Chevron down icon Chevron up icon
Querying and Manipulating Data Using LINQ Chevron down icon Chevron up icon
Improving Performance and Scalability Using Multitasking Chevron down icon Chevron up icon
Practical Applications of C# and .NET Chevron down icon Chevron up icon
Building Websites Using ASP.NET Core Razor Pages Chevron down icon Chevron up icon
Building Websites Using the Model-View-Controller Pattern Chevron down icon Chevron up icon
Building Websites Using a Content Management System Chevron down icon Chevron up icon
Building and Consuming Web Services Chevron down icon Chevron up icon
Building Intelligent Apps Using Machine Learning Chevron down icon Chevron up icon
Building Windows Desktop Apps Chevron down icon Chevron up icon
Building Cross-Platform Mobile Apps Using Xamarin.Forms 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.8
(71 Ratings)
5 star 50.7%
4 star 15.5%
3 star 8.5%
2 star 9.9%
1 star 15.5%
Filter icon Filter
Top Reviews

Filter reviews by




Richie May 10, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Absolutely brilliant, i have been learning C# and have done some video courses and then brought this book. The book goes into detail whichbis brilliant for me. It explains things very well and gives you an idea of when theybwere implemented which add to the experience so you identify how new a feature is.Online courses are good but this book showed me loads of new things that wernt taught the author gives his opinion on somethings also if some techniques are not used often or if theybare frowned upon.It has a good practices section under each topic which tells younwhat you should do.I really like this book it has the detail you would want while teaching the content quickly.It gives reference links for further reading whichbos handy.
Amazon Verified review Amazon
Scott Crowder Sep 14, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm an very experienced C# and .NET engineer and picked up this book to get up to speed on the latest updates to the language and the platform. I found the book easy to navigate. The first few chapters cover the basics. The later chapters do a great job of covering the C# 8 and latest .NET Core features. Mark does an excellent job showing the new features and the why & how to you want to use the latest stuff.
Amazon Verified review Amazon
Christof Stanits Dec 23, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am currently halfway through the book (it is a lot!)No nonsense, straight to topic textbook.It is packed with information and gives you an excellent guideline to learn all you need to know about C# 8.0 and .NET Core 3.0 and how to use it to develop apps.The title is very very long but its really all in there.You might need a very basic understanding of "C#/programming in general" to not feel overwhelmed by its pace, BUT Everything you need to know IS covered.
Amazon Verified review Amazon
Alexandre Malavasi Nov 29, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I just took a look at the preview version of the book C# 8.0 and .NET Core 3.0 — Modern Cross-Platform Development and I found it really impressive, covering almost everything in .NET Core 3.0 and focused on what is really important to know. Written by Mark J. Price, the entire book, with more than 800 pages, contains basic and advanced content, covering all the existent features on .NET Core.I did like the way that the author explored the history of .NET, explaining the differences between .NET Framework and .NET Core. Also, it has tons of examples on how we can migrate our projects to the newest version of .NET Core. That represents a good challenge, mainly in big and complex projects, and the book is really useful to understand the pros and cons of keeping our projects in .NET Framework or migrating it to a newer version.For creating powerful applications using .NET Core, with high performance and world-class quality, it is mandatory to understand entirely what .NET Core offers to you and to understand with details how you can integrate different resources and features of .NET Core in multiples solutions. I think the book meets its objective perfectly.I have really enjoyed the book.I would like to highly recommend this book to everyone who wants to learn C# .NET Core. Very well-drafted book with lots of insights and definitely the best one.
Amazon Verified review Amazon
N Bishai Dec 01, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent and fast delivery
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.