The Weird Things Roslyn Gets up To
Ever wanted to see some strange, interesting, and weird .NET behaviour and features? What about bizarre C# to baffle? If so, then welcome to this little curated and peculiar collection.

We've all seen the JavaScript examples where NaN === NaN
is false
etc. If not, check out some examples in the repo below:
Some you might've seen them, some might be new to you! But what Strange things can we dig up in .NET/C#? Here's a collection I've gathered over the course of 2022.
Smallest Valid C#
At least at the time of .NET 6:
{}
You can see for yourself in this Sharplab.io snippet.
Originally this came to me as a tweet from @Nick_Craver:
{} is a valid program in .NET 6. https://t.co/3e6yQHDdp1 pic.twitter.com/syTNewnvjB
— Nick Craver (@Nick_Craver) April 9, 2022
If you want to dig into it, there is a really fun post from @nietras1 exploring step by step what the smallest valid C# is.

It's All Greek to Me
For those complaining about the !! in C#.
— Llewellyn Pritchard (@leppie) February 11, 2022
A friendly reminder that this is valid C#.
ϼ=ω[ƛ(β:Δ=>Φ??=ω[^++Ʃ]/Ʃ|*&Δ[-0%Ʃ]>>1^Φ??0!&~(δ:Ʃ,^Φ..).δ)..(1_0>.0?Ʃ:0b1)]https://t.co/zzx3vREsBw
Excuse me? I'm extremely happy this came with a Sharplab snippet. Let's break it down. First, looking at the full original code:
using System;
unsafe class Program
{
delegate void bar(int* i);
static Index ƛ(bar β) => default;
static void Main(string[] args)
{
int[] ω = { };
int Ʃ = 42;
int? Φ = 10;
var ϼ = ω;
ϼ=ω[ƛ(β:Δ=>Φ??=ω[^++Ʃ]/Ʃ|*&Δ[-0%Ʃ]>>1^Φ??0!&~(δ:Ʃ,^Φ..).δ)..(1_0>.0?Ʃ:0b1)];
}
}
Then after we make some changes we can begin to more easily pull the example apart:
unsafe class Program
{
delegate void DelegatePointer(int* i);
static Index Indexer(DelegatePointer delegatePointer) => default;
static void Main(string[] args)
{
int[] intArray = { };
int position = 42;
int? nullableValue = 10;
var intArray2 = intArray;
intArray2 = intArray[Indexer(
delegatePointer: x => nullableValue ??= intArray[^++position] / position | *&x[-0 % position] >> 1 ^ nullableValue ?? 0! & ~(δ: position, ^nullableValue..).δ)..(1_0 > .0 ? position : 0b1)];
}
}
Where we have:
- A delegate that takes in a pointer
- The newish
Index
type, introduced to help with Ranges. - A whole bunch of arrays and
int
types
Then we get into the big complex line, which is made up of:
- Array indexing
- The
Index
from earlier - Lambda expressions
- A lot of pointer operators
- And some ranges thrown in
So it's still hard to read, but unobscured by Greek and broken down to the sum of its parts it's a little more manageable and no less fun to show off to others!
Not as Much Greek
Found this in my feed:
Just watching @davidwengier showing me that I no longer know C#. pic.twitter.com/iOEhFJa4Bw
— Damian Brady 🥑 (@damovisa) June 23, 2022
It's a less Greek version of what we just saw. If you zoom in, you can see it's also made up of patterns, and the new range work.
Tolstoy in C#
Makes me smile pic.twitter.com/amyorEU2Do
— Jared Parsons (@jaredpar) May 25, 2022
There's a lot more natural language in C# when compared to lower level languages, or even C# of a decade ago. Since C# 7 we've had Patterns which have been iterated on since meaning we can get to the fun state above.
Sure, there's a little cheating involved as they're not all keywords (check the Sharplab link in the tweet) but it's still fun to let it sink in after seeing it for the first time.
Structs Have a Fluid Identity
Being bored as a nerd, you're bound to be the stereotype at least once, and I went looking for interesting C# snippets and found that Struct
s can reassign their this
value.
Full credit to Omer Mor for this StackOverflow answer:

Maybe there's a cool reason why, but it feels.. weird:
public struct Teaser
{
public void Foo()
{
this = new Teaser();
}
}
There's Never Enough Null Checks
This tweet right here:
Null checking in C# has gotten out of hand. I love the pattern matching and the ability to introduce variables as part of the check but there are too many ways to null check now. #dotnet #csharp pic.twitter.com/NA67zddx6y
— David Fowler 🇧🇧🇺🇸 (@davidfowl) August 1, 2021
Shows a wild amount of null
checks. Whether you believe C# has too many ways to do the same thing or not, this amount is impressive. Though if you frame it so, you can have this as an advantage of C#, where your niche requirement is met by some obscure and valid operation.
In fact, this tweet pushed me to keep a collection of other interesting C# snippets, including the null
checks above:
I did run across this meme that I feel has some truth for the future:
How to check for nulls in C# 15. https://t.co/gIUxTof4XP
— Joseph Woodward (@_josephwoodward) September 4, 2022
What the Compiler Doin'?
Maybe in the future I'll do a full write up exploring these but if you haven't seen, Bartosz Adamczewski does really fascinating writeups and showcasing of compiler manipulations in .NET. You can view all of them on his website or check out a few of his tweets here:
I should probably make a "Compilers are Surprising Magic Show." 🧙♂️
— Bartosz Adamczewski (@badamczewski01) July 6, 2022
Here's my pitch: I show you some reasonable-looking code and change a single line of code, and everything is 10x faster (or 10x slower). pic.twitter.com/awbGowLcmL
Compilers are crazy complex, and this sometimes leads to dumb or funny behavior (or both).
— Bartosz Adamczewski (@badamczewski01) July 6, 2022
Here's a funny example of performance degradation in C# .NET#dotnet pic.twitter.com/1pcpzjBsip
Here's another interesting quirk about nullables in C#
— Bartosz Adamczewski (@badamczewski01) July 1, 2022
1/X#dotnet pic.twitter.com/hWIcUumS6H
To Conclude
Since getting deeper into the .NET community in 2022, I've been collecting little snippets of oddity and fun. I'm sure there's a lot more out there and maybe in the future I'll collect enough to write up another post. I hope you found this as enjoyable as I do!