Book Image

C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition

By : Mark J. Price
5 (1)
Book Image

C# 10 and .NET 6 – Modern Cross-Platform Development - Sixth Edition

5 (1)
By: Mark J. Price

Overview of this book

Extensively revised to accommodate all the latest features that come with C# 10 and .NET 6, this latest edition of our comprehensive guide will get you coding in C# with confidence. You’ll learn object-oriented programming, writing, testing, and debugging functions, implementing interfaces, and inheriting classes. The book covers the .NET APIs for performing tasks like managing and querying data, monitoring and improving performance, and working with the filesystem, async streams, and serialization. You’ll build and deploy cross-platform apps, such as websites and services using ASP.NET Core. Instead of distracting you with unnecessary application code, the first twelve chapters will teach you about C# language constructs and many of the .NET libraries through simple console applications. In later chapters, having mastered the basics, you’ll then build practical applications and services using ASP.NET Core, the Model-View-Controller (MVC) pattern, and Blazor.
Table of Contents (20 chapters)
19
Index

Writing and calling methods

Methods are members of a type that execute a block of statements. They are functions that belong to a type.

Returning values from methods

Methods can return a single value or return nothing:

  • A method that performs some actions but does not return a value indicates this with the void type before the name of the method.
  • A method that performs some actions and returns a value indicates this with the type of the return value before the name of the method.

For example, in the next task, you will create two methods:

  • WriteToConsole: This will perform an action (writing some text to the console), but it will return nothing from the method, indicated by the void keyword.
  • GetOrigin: This will return a text value, indicated by the string keyword.

Let's write the code:

  1. In Person.cs, add statements to define the two methods that I described earlier, as shown in the following code: ...