.NET Core

C# 8 nullable reference types

C# 8 nullable reference types

In the previous article, we discussed C# 8 default interface methods. In this article, we’ll look at C# 8 nullable reference types. Reference types refer to an object that is on the heap. When there is no object to refer to, the value is null. Sometimes null is an acceptable value, but often it is an illegal value that leads to ArgumentNullExceptions and NullReferenceExceptions.

C# 8 finally gives us the ability to express whether a variable shouldn’t be null, and when it can be null. Based on these annotations, the compiler will warn you when you are potentially using a null reference, or passing a null reference to a function that won’t accept it.

Continue reading “C# 8 nullable reference types”

Share
C# 8 default interface methods

C# 8 default interface methods

In the previous articles, we discussed C# 8 async streams and pattern matching. In this article, we’ll look at C# 8 default interface methods.

Extending interfaces

Before C# 8, it was not possible to add members to an interface without breaking the classes that implement the interface. Because interface members were abstract, classes needed to provide an implementation. C# 8 allows us to extend an interface and provide a default implementation. The runtime (which also needs to support this feature) uses the default implementation when the class does not provide it:

interface IOutput
{
    void PrintMessage(string message);
    void PrintException(Exception exception)
        => PrintMessage($"Exception: {exception}");
}
class ConsoleOutput : IOutput
{
    public void PrintMessage(string message)
        => Console.WriteLine(message);
}

In this example, ConsoleOutput does not provide an implementation for PrintException. When PrintException is called against a ConsoleOutput instance, the default method from the IOutput interface will be called. ConsoleOutput might provide its own implementation.

Continue reading “C# 8 default interface methods”

Share
C# 8 asynchronous streams

C# 8 asynchronous streams

.NET Core 3.1 (December 2019) includes support for C# 8, a new major
version of the C# programming language. In this series of articles, we’ll look at the new features in .NET’s main programming language. This first article, in particular, looks at asynchronous streams. This feature makes it easy to create and consume asynchronous enumerables, so before getting into the new feature, you first need to understand the IEnumerable interface.

Note: C# 8 can be used with the .NET Core 3.1 SDK, which is available on Red Hat Enterprise Linux, Fedora, Windows, macOS, and on other Linux distributions.

A brief history of IEnumerable

The classic IEnumerable<T> has been around since .NET Framework 2 (2005). This interface provides us with a type-safe way to iterate over any collection.

The iteration is based on the IEnumerator<T> type:

Continue reading “C# 8 asynchronous streams”

Share
Tracing .NET Core applications

Tracing .NET Core applications

In this article, we’ll look at different ways of collecting and inspecting events from the .NET Core runtime and base class library (BCL).

EventListener

The EventListener class allows us to get events of the running application. Let’s learn how to use it with an example application. Our application performs an HTTP get and prints the length of the received response.

Continue reading “Tracing .NET Core applications”

Share
Getting started with .NET Core in Red Hat Enterprise Linux 8.1

Getting started with .NET Core in Red Hat Enterprise Linux 8.1

One exciting feature in the recent release of Red Hat Enterprise Linux 8.1 is .NET Core 3.0. In this article, we will take a quick look at using .NET Core on Red Hat Enterprise Linux 8. We will cover installing .NET Core RPMs and using the RHEL-based Universal Base Image container images.

Installing .NET Core packages on RHEL 8

With RHEL 8, .NET Core is included in the AppStream repositories, which are enabled by default on RHEL 8 systems. At least two versions of .NET Core are already available on RHEL 8, and more will be added as they are released.

Continue reading “Getting started with .NET Core in Red Hat Enterprise Linux 8.1”

Share
.NET Core 3.0 for Red Hat Enterprise Linux 7 now available

.NET Core 3.0 for Red Hat Enterprise Linux 7 now available

We are very excited to announce the general availability of .NET Core 3.0 for Red Hat Enterprise Linux 7! .NET Core is the open source, cross-platform .NET platform for building microservices. .NET Core is designed to provide the best performance at scale for applications that use microservices and containers.

.NET Core 3.0 is available today on Red Hat Enterprise Linux 7 via “yum” in the /dotnet repo, and in container images from the Red Hat Container Catalog. Availability for Red Hat Enterprise Linux 8 will come with the release of RHEL 8.1 in Application Streams.

Continue reading “.NET Core 3.0 for Red Hat Enterprise Linux 7 now available”

Share