Professional C# 6 and .NET Core 1.0. Christian Nagel

Читать онлайн.
Название Professional C# 6 and .NET Core 1.0
Автор произведения Christian Nagel
Жанр Зарубежная образовательная литература
Серия
Издательство Зарубежная образовательная литература
Год выпуска 0
isbn 9781119096634



Скачать книгу

C# 6

      Dictionary initializers are covered in Chapter 11, “Collections.”

      Exception Filters

      Exception filters allow you to filter exceptions before catching them.

      In C# 5

      In C# 6

      A big advantage of the new syntax is not only that it reduces the code length but also that the stack trace is not changed – which happens with the C# 5 variant. Exception filters are covered in Chapter 14, “Errors and Exceptions.”

      Await in Catch

      await can now be used in the catch clause. C# 5 required a workaround.

      In C# 5

      In C# 6

      This feature doesn’t need an enhancement of the C# syntax; it’s functionality that’s working now. This enhancement required a lot of investment from Microsoft to make it work, but that really doesn’t matter to you using this platform. For you, it means less code is needed – just compare the two versions.

      NOTE The new C# 6 language features are covered in the mentioned chapters, and in all chapters of this book the new C# syntax is used.

What’s New with the Universal Windows Platform

      Windows 8 introduced a new programming API, the Windows Runtime. Applications using the Windows Runtime could be made available via the Microsoft Store and were known with many different names. It started with Metro apps or Metro style apps, and they are also known as Modern apps, Windows Store apps (although they can also be installed with PowerShell scripts without using the store), and Universal apps. Probably there are some names I missed. Nowadays, these are just Windows apps, running on the Universal Windows Platform (UWP).

      The idea of these apps was to allow end users to find them easily via the Microsoft store and to offer a touch-friendly environment, a modern user interface that looks nice and smooth and allows fluid interactions, and apps that can be trusted. More than that, the users who already know the Windows user interfaces should be attracted to using the new environment.

      The first version of the design guidelines was very restrictive and had some flaws. How can I search for stuff in the app? Many users didn’t find the charms bar on the right side, and found out it allowed searching in many apps. Windows 8.1 moved the search to a search box directly on the desktop. Also, users often didn’t find the app bar located at the top or bottom if they didn’t perform a touch gesture from top to bottom or bottom to top.

      Windows 10 made the design much more open. You can use the things that are useful for your apps and can decide on the user interface as it best matches your users and apps. Of course, it’s still best to create a nice looking, smooth, and fluid design. It’s better for having users happily interacting with the app, and they should not have a hard time finding out how things can be done.

      The new Windows Runtime, Windows Runtime 3.0, steps on the predecessor versions to define an XAML user interface, implements an application lifecycle, and allows background functionality, sharing of data between applications, and more. Indeed, the new version of the runtime offers more features in all the areas.

      Windows apps now make use of .NET Core. You can use the same .NET libraries available via NuGet packages with Windows apps. Finally, native code gets compiled for a faster app startup and less memory consumption.

      What might be even more important than the additional features offered is the universality that’s now available. The first update of Visual Studio 2013 included a new project type for Windows 8 apps: Universal apps. Here, Universal apps have been done with three projects: one project for the Windows app, one project for the Windows phone app, and a shared code project. It was possible to even share XAML code between these platforms. The new Universal project template consists of one project. You can use the same binary not only for Windows and Windows Phone, but also for the Xbox, Internet of Things (IoT) devices, the HoloLens, and more. Of course, these different platforms offer features that are not available everywhere, but using this differing feature you can still create one binary image that runs on every Windows 10 device.

What You Need to Write and Run C# Code

      .NET Core runs on Windows, Linux, and Mac operating systems. You can create and build your programs on any of these operating systems using Visual Studio Code (https://code.visualstudio.com). The best developer tool to use, and the tool used with this book, is Visual Studio 2015. You can use Visual Studio Community 2015 edition (https://www.visualstudio.com), but some features shown are available only with the Enterprise edition of Visual Studio. It will be mentioned where the Enterprise edition is needed. Visual Studio 2015 requires the Windows operating system. Windows 8.1 or later is required.

      To build and run WPF applications shown in this book, you need a Windows platform. Running WPF applications is still supported on Windows 7.

      For building Universal Windows apps, you can use Windows 8.1 with Visual Studio, but for testing and running these apps, you need a Windows 10 device.

What This Book Covers

      This book starts by reviewing the overall architecture of .NET in Chapter 1 to give you the background you need to write managed code. You’ll get an overview about the different application types and learn how to compile with the new development environment CLI. After that, the book is divided into a number of sections that cover both the C# language and its application in a variety of areas.

      Part I: The C# Language

      This section gives a good grounding in the C# language. This section doesn’t presume knowledge of any particular language, although it does assume you are an experienced programmer. You start by looking at C#’s basic syntax and data types and then explore the object-oriented features of C# before looking at more advanced C# programming topics like delegates, lambda expressions, Language Integrated Query (LINQ), reflection, and asynchronous programming.

      Part II: .NET Core and Windows Runtime

      This section starts with tools, and it looks at the main integrated development environment (IDE) utilized by C# developers worldwide: Visual Studio 2015. You’ll learn about the tools available with the Enterprise edition of Visual Studio in Chapter 17, “Visual Studio 2015.”

      You also learn what’s behind the C# compiler and how you can use the .NET Compiler Platform to change your code programmatically in Chapter 18, “.NET Compiler Platform.”

      When you’re creating functionality with C# code, don’t skip the step of creating unit tests. It takes more time in the beginning, but over time you’ll see advantages when you add functionality and maintain code. Chapter 19, “Testing,” covers creating unit tests, web tests, and coded UI tests.

      Chapters 20 to 28 cover topics from .NET Core and the Windows Runtime that are independent of application types. In Chapter 20, “Diagnostics and Application Insights,” you’ll learn writing diagnostic information from the application that can also be used in the production environment. Chapters 21, “Tasks and Parallel Programming,” and 22, “Task Synchronization,” cover parallel programming using the Task Parallel Library (TPL) as well as various objects for synchronization. In Chapter 23, “Files and Streams,” you’ll read about accessing the file system and reading files and directories. Using streams, you’ll learn using both streams from the System.IO namespace and streams from the Windows Runtime for programming Windows apps. Chapter 24, “Security,” makes use of streams when you learn about security and how to encrypt data and allow for secure conversion. You’ll also learn the core foundation of networking using sockets, as