Book Image

C# 7 and .NET: Designing Modern Cross-platform Applications

By : Mark J. Price, Ovais Mehboob Ahmed Khan
Book Image

C# 7 and .NET: Designing Modern Cross-platform Applications

By: Mark J. Price, Ovais Mehboob Ahmed Khan

Overview of this book

C# is a widely used programming language, thanks to its easy learning curve, versatility, and support for modern paradigms. The language is used to create desktop apps, background services, web apps, and mobile apps. .NET Core is open source and compatible with Mac OS and Linux. There is no limit to what you can achieve with C# and .NET Core. This Learning Path begins with the basics of C# and object-oriented programming (OOP) and explores features of C#, such as tuples, pattern matching, and out variables. You will understand.NET Standard 2.0 class libraries and ASP.NET Core 2.0, and create professional websites, services, and applications. You will become familiar with mobile app development using Xamarin.Forms and learn to develop high-performing applications by writing optimized code with various profiling techniques. By the end of C# 7 and .NET: Designing Modern Cross-platform Applications, you will have all the knowledge required to build modern, cross-platform apps using C# and .NET. This Learning Path includes content from the following Packt products: • C# 7.1 and .NET Core 2.0 - Modern Cross-Platform Development - Third Edition by Mark J. Price • C# 7 and .NET Core 2.0 High Performance by Ovais Mehboob Ahmed Khan
Table of Contents (25 chapters)
Title Page
Copyright
About Packt
Contributors
Preface
16
Designing Guidelines for .NET Core Application Performance
Index

Looking for help


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

Microsoft Docs and MSDN

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

Visual Studio 2017 is integrated with MSDN and Docs, so if you press F1 inside a C# keyword or type, then it will open your browser and take you to the official documentation.

Note

In Visual Studio Code, pressing F1 shows the Command Palette. It does not support context-sensitive help.

Go to definition

Another useful keystroke in both Visual Studio 2017 and Visual Studio Code is F12. This will show what the public definition of the type looks like by reading the metadata in the compiled assembly. Some tools will even reverse-engineer from the metadata and IL code back into C# for you.

Enter the following code, click inside int, and then press F12 (or right-click and choose Go To Definition):

int z;

In the new code window that appears, you can see that int is in the mscorlib.dll assembly; it is named Int32; it is in the System namespace; and int is therefore an alias for System.Int32, as shown in the following screenshot:

>

Microsoft defined int using a struct keyword, meaning that int is a value type stored on the stack. You can also see that int implements interfaces such as IComparable and has constants for its maximum and minimum values.

In the code editor window, scroll down to find the Parse methods and in Visual Studio 2017, you will need to click on the small box with a plus symbol in them to expand the code like I have done in the following screenshot:

In the comment, you will see that Microsoft has documented what exceptions might occur if you call this method (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.

Stack Overflow

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

Go to >DuckDuckGo.com and enter the following query:

!so securestring

 

You will get the following results:

Google

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

For example, if you are searching for information about garbage collection using a simple Google query, you will 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:

We can improve the search by restricting it to a useful site such as Stack Overflow, as shown in the following screenshot:

We can improve the search even more by removing languages that we might not care about such as C++, as shown in the following screenshot:

Subscribing to blogs

To keep up to date with .NET, an excellent blog to subscribe to is the official .NET Blog written by the .NET engineering teams.  (https://blogs.msdn.microsoft.com/dotnet/).

Design patterns

A design pattern is a general solution to a common problem. Programmers have been solving the same problems over and over. When the community discovers a good reusable solution, we call it a design pattern. Many design patterns have been documented over the years.

Navigate to the following link to read about common design patterns:

https://en.wikipedia.org/wiki/Software_design_pattern#Classification_and_list

Microsoft has a group called patterns & practices that specializes in documenting and promoting design patterns for Microsoft products.

Note

Good Practice Before writing new code, search to see if someone else has already solved the problem in a general way.

Singleton pattern

One of the most common patterns is the Singleton pattern. Examples of Singleton in .NET are the Console and Math types.

Note

Read more about the Singleton pattern at: https://en.wikipedia.org/wiki/Singleton_pattern