C# 7.1 - Everything You Need To Know

Visual Studio 2017.3 brought with it the first minor update to the C# language, C# 7.1. This update adds four new features to C#: async main, target-typed default literals, tuple name inference, and generic support for pattern-matching.

In this post, you'll learn how to enable the new C# 7.1 language features in your …

Read More

Upgrading to .NET Core and .NET Standard Made Easy

With the release of .NET Core 2.0 and .NET Standard 2.0, now is a great time to consider upgrading your projects to .NET Core and your libraries to .NET Standard.

By upgrading your projects to .NET Core 2.0 you get cross-platform support and higher performance. By upgrading your libraries to .NET Standard you get greater compatibility and ensure they can be used in projects targeting …

Read More

Understanding .NET Standard - An Interface Not An Implementation

With so many different platforms, standards, and frameworks, how do you make sense of it all? There is .NET Framework, .NET Core, and .NET Standard before you even get to Mono and Xamarin.

What is the difference, which do I need, what is .NET Standard? When do I use .NET Standard? If you're confused, then you're not alone and this post is for you.

In this post, I explain .NET …

Read More

What is .NET? Framework or Platform?

You'll often hear the terms framework and platform used interchangeably. This can be very confusing. You'll hear that .NET Core is a platform. Then you'll read that .NET Core is cross-platform. Next, you'll learn that .NET Core is a framework. And it doesn't help that framework is part of the name of the original full .NET Framework.

In this post, I explain …

Read More

Fixing the Duplicate Content Error after Upgrading Visual Studio 2017

If you have an ASP.NET Core project that was working fine and you upgrade to Visual Studio 2017, you're bound to hit the Duplicate Content compile error. This will affect you regardless of which framework you use and affects both .NET Framework and .NET Core projects, even if you haven't upgraded to .NET Core 2.0.

In this post, I explain why it happens, why the change has been made, …

Read More

Getting Started with Visual Studio 2017 v15.3

Microsoft has just released a round of major updates to the .NET stack. Visual Studio 2017 gets its biggest update yet. C# gets its first update to C# 7.1 as part of the faster release cadence enabled by Roslyn. The new open source frameworks .NET Core and ASP.NET Core both get their 2.0 releases and .NET Standard 2.0 has arrived to unify everything.

Over the last 16 hours I've been …

Read More

Maximizing Throughput - The Overhead of 1 Million Tasks

I recently needed to choose between two competing designs: a simple one that needed millions of tasks or a complex one that needed only a few processing threads.

Plan A was to leverage the power of Task-based asynchronous programming in .NET to create a simple solution that had tasks waiting on a mix of other tasks, timers, events, and more; but, it would need millions of tasks, all …

Read More

Better Benchmarking with Additive and Multiplicative Baselines

In my recent blog posts I've been benchmarking different ways to cast in C#. If you have a keen eye, you may have noticed that the results do not match up. In one experiment, a direct cast (no cast at all) takes 15ns, while in another experiment, a more complicated generic cast

Read More

Covariant and Contravariant Casting is 3x Slower than Dynamic

Previously, we saw that covariant and contravariant casting is slow: 100x slower than normal casting. It turns out that covariant and contravariant casting is even slower than casting to dynamic and using dynamic dispatch: 3x slower than dynamic. This is significant as IEnumerable<T>

Read More

Casting to IEnumerable<T> is Two Orders of Magnitude Slower

Casting to generic interfaces that use covariance or contravariance is two orders of magnitude slower than normal casts in C#. This means casting to IEnumerable<T> is two orders of magnitude slower too. This result was quite unexpected and very surprising.

In this post, I investigate the cost of casting to implementations, interfaces, generic interfaces, covariant …

Read More