C# is now ‘C#++’

C# language is evolving, continuously, that I call it C#++

Joni 【ジョニー】
2 min readApr 29, 2018

While some new languages were created to eventually replace its successor (like Swift, and perhaps Kotlin, …), C# itself is evolving, continuously.

The ECMA standard lists these design goals for C#:

The language is intended to be a simple, modern, general-purpose, object-oriented programming language.

…intended to be simple!

If you have been following the latest C# 7.2 features here, you know that the language is getting more complex now.

In addition to ref and out, C# now has in, ref readonly, readonly struct, ref struct. Err, What?

These enhancements to the C# language are designed for performance critical algorithms where memory allocations can be critical to achieving the necessary performance. You may find that you don’t often use these features in the code you write. However, these enhancements have been adopted in many locations in the .NET Framework.

Okay, noted.
And the beauty of C# is, you can always go low-level with unsafe.
For example:

From https://twitter.com/matthewwarren/status/989098535940513792

That “pointer manipulation” reminds me of my old “Hello world” C++ art code I wrote back in 2003.

C++ Art: Hello world

With C# 7.2 Span<T> and Memory<T> in .NET Core 2.1, we don’t really have to go low-level to optimize our code. We get the best of both worlds: performance boost and easier to maintain code. Your boss will be happy.

See the latest performance improvements in .NET Core 2.1:

Speaking of readonly struct, do you know that you can write an extension method for structs that takes this by value, by in or by ref?

From https://twitter.com/STeplyakov/status/987161117964120064

Not really new, but another interesting thing about struct worth to point out:

From https://twitter.com/STeplyakov/status/988299494537084929

If you are dealing with those kinds of things, then definitely check out the mentioned library here: https://github.com/SergeyTeplyakov/ObjectLayoutInspector

Also from the same author, https://twitter.com/STeplyakov is working on a set of Roslyn-based analyzers that will help you to write correct code. The idea is similar to Google’s error-prone but focusing on correctness (and, maybe, performance) of C# programs.
https://github.com/SergeyTeplyakov/ErrorProne.NET

Last but not least, Nullable Reference Types is coming to C# 8.0!

For a complete status of C# language feature, see:
https://github.com/dotnet/roslyn/blob/master/docs/Language%20Feature%20Status.md

Catch up with the latest .NET technology is hard. I plan to write about it in the future posts. You can follow me on twitter.

--

--