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

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



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

with minor enhancements.

      NOTE Inheritance is discussed in Chapter 4, “Inheritance”; delegates and events are covered in Chapter 9, “Delegates, Lambdas, and Events.”

      NOTE Every new release of .NET has been accompanied by a new version of the book Professional C#. With .NET 1.0, the book was already in the second edition as the first edition had been published with Beta 2 of .NET 1.0. You’re holding the 10th edition of this book in your hands.

      C# 2 and .NET 2 with Generics

      C# 2 and .NET 2 was a huge update. With this version, a change to both the C# programming language and the IL code had been made; that’s why a new CLR was needed to support the IL code additions. One big change was generics. Generics make it possible to create types without needing to know what inner types are used. The inner types used are defined at instantiation time, when an instance is created.

      This advance in the C# programming language also resulted in many new types in the Framework – for example, new generic collection classes found in the namespace System.Collections.Generic. With this, the older collection classes defined with 1.0 are rarely used with newer applications. Of course, the older classes still work nowadays, even with the new .NET Core version.

      NOTE Generics are used all through the book, but they’re explained in detail in Chapter 6, “Generics.” Chapter 11, “Collections,” covers generic collection classes.

      .NET 3 – Windows Presentation Foundation

      With the release of .NET 3.0 no new version of C# was needed. 3.0 was only a release offering new libraries, but it was a huge release with many new types and namespaces. Windows Presentation Foundation (WPF) was probably the biggest part of the new Framework for creating Windows desktop applications. Windows Forms wrapped the native Windows controls and was based on pixels, whereas WPF was based on DirectX to draw every control on its own. The vector graphics in WPF allow seamless resizing of every form. The templates in WPF also allow for complete custom looks. For example, an application for the Zurich airport can include a button that looks like a plane. As a result, applications can look very different from the traditional Windows applications that had been developed up to that time. Everything below the namespace System.Windows belongs to WPF, with the exception of System.Windows.Forms. With WPF the user interface can be designed using an XML syntax: XML for Applications Markup Language (XAML).

      Before .NET 3, ASP.NET Web Services and .NET Remoting were used for communicating between applications. Message Queuing was another option for communicating. The various technologies had different advantages and disadvantages, and all had different APIs for programming. A typical enterprise application had to use more than one communication API, and thus it was necessary to learn several of them. This was solved with Windows Communication Foundation (WCF). WCF combined all the options of the other APIs into the one API. However, to support all of the features WCF has to offer, you need to configure WCF.

      The third big part of the .NET 3.0 release was Windows Workflow Foundation (WF) with the namespace System.Workflow. Instead of creating custom workflow engines for several different applications (and Microsoft itself created several workflow engines for different products), a workflow engine was available as part of .NET.

      With .NET 3.0, the class count of the Framework increased from 8,000 types in .NET 2.0 to about 12,000 types.

      NOTE In this book, WPF is covered in Chapters 29, 30, 31, 34, 35, and 36. You can read information about WCF in Chapter 44, “Windows Communication Foundation.”

      C# 3 and .NET 3.5 – LINQ

      .NET 3.5 came together with a new release of C# 3. The major enhancement was a query syntax defined with C# that allows using the same syntax to filter and sort object lists, XML files, and the database. The language enhancements didn’t require any change to the IL code as the C# features used here are just syntax sugar. All of the enhancements could have been done with the older syntax as well, just a lot more code would be necessary. The C# language makes it really easy to do these queries. With LINQ and lambda expressions, it’s possible to use the same query syntax and access object collections, databases, and XML files.

      For accessing the database and creating LINQ queries, LINQ to SQL was released as part of .NET 3.5. With the first update to .NET 3.5, the first version of Entity Framework was released. Both LINQ to SQL and Entity Framework offered mapping of hierarchies to the relations of a database and a LINQ provider. Entity Framework was more powerful, but LINQ to SQL was simpler. Over time, features of LINQ to SQL have been implemented in Entity Framework, and now this one is here to stay. (Nowadays it looks very different from the first version released.)

      Another technology introduced as part of .NET 3.5 was the System.AddIn namespace, which offers an add-in model. This model offers powerful features that run add-ins even out of process, but it is also complex to use.

      NOTE LINQ is covered in detail in Chapter 13, “Language Integrated Query.” The newest version of the Entity Framework is very different from the .NET 3.5 release; it’s described in Chapter 38, “Entity Framework Core.”

      C# 4 and .NET 4 – Dynamic and TPL

      The theme of C# 4 was dynamic – integrating scripting languages and making it easier to use COM integration. C# syntax has been extended with the dynamic keyword, named and optional parameters, and enhancements to co- and contra-variance with generics.

      Other enhancements have been made within the .NET Framework. With multi-core CPUs, parallel programming had become more and more important. The Task Parallel Library (TPL), with abstractions of threads using Task and Parallel classes, make it easier to create parallel running code.

      Because the workflow engine created with .NET 3.0 didn’t fulfill its promises, a completely new Windows Workflow Foundation was part of .NET 4.0. To avoid conflicts with the older workflow engine, the newer one is defined in the System.Activity namespace.

      The enhancements of C# 4 also required a new version of the runtime. The runtime skipped from version 2 to 4.

      With the release of Visual Studio 2010, a new technology shipped for creating web applications: ASP.NET MVC 2.0. Unlike ASP.NET Web Forms, this technology required programming HTML and JavaScript, and it used C# and .NET with server-side functionality. As this technology was very new as well as being out of band (OOB) to Visual Studio and .NET, ASP.NET MVC was updated regularly.

      NOTE The dynamic keyword of C# 4 is covered in Chapter 16, “Reflection, Metadata, and Dynamic Programming.” The Task Parallel Library is covered in Chapter 21, “Tasks and Parallel Programming.”

      Version 5 of ASP.NET and Version 6 of ASP.NET MVC are covered in Chapter 40, “ASP.NET Core,” and Chapter 41, “ASP.NET MVC.”

      C# 5 and Asynchronous Programming

      C# 5 had only two new keywords: async and await. However, they made programming of asynchronous methods a lot easier. As touch became more significant with Windows 8, it also became a lot more important to not block the UI thread. Using the mouse, users are accustomed to scrolling taking some time. However, using fingers on a touch interface that is not responsive is really annoying.

      Windows 8 also introduced a new programming interface for Windows Store apps (also known as Modern apps, Metro apps, Universal Windows apps, and, more recently, Windows apps): the Windows Runtime. This is a native runtime that looks like .NET by using language projections. Many of the WPF controls have been redone for the new runtime, and a subset of the .NET Framework can be used with such apps.

      As the System.AddIn framework was much too complex and slow, a new composition framework was created with .NET 4.5: Managed Extensibility Framework with the namespace System.Composition.

      A new version of platform-independent communication is offered by the ASP.NET Web API. Unlike WCF, which offers stateful and stateless services as well as many different network protocols, the ASP.NET Web API is a lot simpler and based on the Representational State Transfer (REST) software