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

Читать онлайн книгу.

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


Скачать книгу
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 be accessed. With this, name changes are not missed with refactoring:

      In C# 5

      In C# 6

      The nameof operator is covered in Chapter 8, “Operators and Casts.”

      Null Propagation Operator

      The null propagation operator simplifies null checks:

      In C# 5

      In C# 6

      The new syntax also has an advantage for firing events:

      In C# 5

      In C# 6

      The null propagation operator is covered in Chapter 8.

      String Interpolation

      The string interpolation removes calls to string.Format. Instead of using numbered format placeholders in the string, the placeholders can include expressions:

      In C# 5

      In C# 6

      The C# 6 sample is reduced that much compared to the C# 5 syntax because it uses not only string interpolation but also an expression-bodied method.

      String interpolation can also use string formats and get special features on assigning it to a FormattableString. String interpolation is covered in Chapter 10, “Strings and Regular Expressions.”

      Dictionary Initializers

      Dictionaries can now be initialized with a dictionary initializer – similar to the collection initializer.

      In C# 5

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