Professional C# 6 and .NET Core 1.0. Christian Nagel
Чтение книги онлайн.

Читать онлайн книгу Professional C# 6 and .NET Core 1.0 - Christian Nagel страница 3

СКАЧАТЬ to older .NET runtime versions because my provider didn’t support the newest one. With .NET Core, the runtime is delivered with the application.

      When ASP.NET was built, compatibility with the predecessor technology Active Server Pages (ASP) that was built with JavaScript or VBScript code running on the server was an important aspect. Nowadays this is not needed anymore. ASP.NET Web Forms was built with the idea that the developer doesn’t need to know anything about JavaScript and HTML, and everything could be done with server-side code. Now, because of the huge number of JavaScript frameworks and enhancements in HTML, more control on JavaScript and HTML is needed.

      With the new version of ASP.NET, performance has a big role in the framework architecture. You only have performance impacts for the things you really need. In case you don’t have static files with your web application, you have to explicitly decide on using it, otherwise you don’t pay a performance impact for this. With fine-grained control you can decide what features you need.

      To get an even bigger performance improvement,NET Core can be built to native code. This is possible not only on Windows but also on Linux and Mac systems. With this you can get performance improvement especially on program startup, and you use less memory.

      Now there’s an issue with legacy applications. Most applications can’t switch that easily to .NET Core. The full .NET Framework – running just on Windows – is evolving as well. It’s not evolving in such big steps as .NET Core, but it is a mature framework. At the time of this writing,NET 4.6.1 is released, with small updates compared to the previous versions. Applications that have been written with Windows Forms or ASP.NET Web Forms still need to use the full framework, but they can take advantage of the enhancements of .NET 4.6.1. Using .NET 4.6.1, you can also use NuGet packages built for .NET Core. Many new NuGet packages are built in a portable manner. With ASP.NET MVC 5 web applications you can also decide to change to ASP.NET MVC 6 running on ASP.NET Core 1.0. ASP.NET Core 1.0 allows using either .NET Core or .NET 4.6. This can make the switch easier. However, for running ASP.NET MVC on Linux, you need to migrate the ASP.NET MVC application to use .NET Core, but running on Linux wasn’t available previously as well.

      Here’s a summary of some of the features of .NET Core:

      • .NET Core is open source.

      • Smaller NuGet packages allow for faster innovation.

      • .NET Core supports multiple platforms.

      • .NET Core can compile to native code.

      • ASP.NET can run on Windows and Linux.

      • Existing applications still run and can evolve into the future.

      As you can see with the features of .NET Core, this technology made the biggest change for .NET in the history since the first version of .NET. This is a new start. From here we can continue our journey on new developments in a fast pace.

The Significance of C#

      When C# was released in the year 2002, it was a language developed for the .NET Framework. C# was designed with ideas from C++, Java, and Pascal. Anders Hejlsberg had come to Microsoft from Borland and brought experience with language development of Delphi. At Microsoft, Hejlsberg worked on Microsoft’s version of Java, named J++, before creating C#.

      C# started not only as an object-oriented general purpose programming language but was a component-based programming language that supported properties, events, attributes (annotations), and building assemblies (binaries including metadata).

      Over time, C# was enhanced with generics, Language Integrated Query (LINQ), lambda expressions, dynamic features, and easier asynchronous programming. C# is not an easy programming language because of the many features it offers, but it’s continuously evolving with features that are practical to use. With this, C# is more than an object-oriented or component-based language; it also includes ideas of functional programming – things that are of practical use for a general-purpose language developing all kind of applications.

What’s New in C# 6

      With C# 6 a new C# compiler is available. It’s not only that a source code cleanup was done; the features of the compiler pipeline can now be used from custom programs, and are used by many features of Visual Studio.

      This new compiler platform made it possible to enhance C# with many new features. Although there’s not a feature with such an impact as LINQ or the async keyword, the many enhancements increase developer productivity. What are the changes of C# 6?

      static using

      The static using declaration allows invoking static methods without the class name:

      In C# 5

      In C# 6

      The using static keyword is covered in Chapter 2, “Core C#.”

      Expression-Bodied Methods

      With expression-bodied methods, a method that includes just one statement can be written with the lambda syntax:

      In C# 5

      In C# 6

      Expression-bodied methods are covered in Chapter 3, “Objects and Types.”

      Expression-Bodied Properties

      Similar to expression-bodied methods, one-line properties with only a get accessor can be written with the lambda syntax:

      In C# 5

      In C# 6

      Expression-bodied properties are covered in Chapter 3.

      Auto-Implemented Property Intializers

      Auto-implemented properties can be initialized with a property initializer:

      In C# 5

      In C# 6

      Auto-implemented property initializers are covered in Chapter 3.

      Read-Only Auto Properties

      To implement read-only properties, C# 5 requires the full property syntax. With C# 6, you can do this using auto-implemented properties:

      In C# 5

      In C# 6

      Read-only auto properties are covered in Chapter 3.

      nameof Operator

      With the new nameof operator, names of fields, properties, methods, or types can СКАЧАТЬ