Live data from Hacker News

.NET (OK, C#) finally gets union types

andrewlock.net

11–20 of 300 posts

Re: .NET (OK, C#) finally gets union types

#11

I mean yes, but also: uh-oh. I'm looking forward to reading some code that is even more confusing than the code I'm already reading. Not entirely convinced that I see the usecase that makes up for the potential madness.

Unions are simpler than subclasses and more powerful than enums, so the use cases are plentiful. This should reduce the proliferation of verbose class hierarchies in C#. Algebraic data types (i.e. records and unions) can usually express domain models much more succinctly than traditional OO.

Re: .NET (OK, C#) finally gets union types

#13
post #8

I used to see some excitement around .net core several years ago. I haven’t heard or seen much in the wild. Is anyone using .net on systems other than windows nowadays?

Yes, lambda's and our dev's use mac's so it enables that. We deploy some apps to some unix based server as well but the company is mostly windows servers anyway.

Re: .NET (OK, C#) finally gets union types

#14
post #5

AFAICT, this means you won’t be able to define Either , which is definitely a thing you sometimes want to do.

C# is strongly-typed, not stringly-typed. The point of the union is to list possible outcomes as defined through their respective types.

The idiomatic way to do this would be to parse, don't validate [1] each string into a relevant type with a record or record struct. If you just wanted to return two results of the same type, you'd wrap them in a named tuple or a record that represented the actual meaning.

[1] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

Re: .NET (OK, C#) finally gets union types

#15
post #9
post #7

Earlier quoted context omitted.

Union/sum types are generally a good thing. Even Java added them. They tend to be worth “the madness”. Now the rest of all the crazy C# features might be a different question.

What features do you see as crazy?

All the weird cruft around nullability, for starters. Once again confirming that allowing null references is usually a mistake.

Re: .NET (OK, C#) finally gets union types

#16
post #5

AFAICT, this means you won’t be able to define Either , which is definitely a thing you sometimes want to do.

It seems like if you wrap both in a record then it should be possible:

    public record Left(T Value);
    public record Right(T Value);
    public union Either(Left, Right);

Re: .NET (OK, C#) finally gets union types

#17
post #8

I used to see some excitement around .net core several years ago. I haven’t heard or seen much in the wild. Is anyone using .net on systems other than windows nowadays?

Wwwuuuuuaaahhhhh! (making a big wild excited noise using asp.net core exclusively on Linux servers since 2017)

Re: .NET (OK, C#) finally gets union types

#18

I mean yes, but also: uh-oh. I'm looking forward to reading some code that is even more confusing than the code I'm already reading. Not entirely convinced that I see the usecase that makes up for the potential madness.

A common use case for the sum type is to define a Result (or Either) type. Now, C# not having checked exceptions is not as much in need for one as Java is, but I could still imagine it being useful for stream like constructs.

Re: .NET (OK, C#) finally gets union types

#20
post #10
post #8

I used to see some excitement around .net core several years ago. I haven’t heard or seen much in the wild. Is anyone using .net on systems other than windows nowadays?

It’s huge in the game dev world, with Unity and Godot. .net also had a reasonable community on mobile for a while thanks to Xamarin, but I cannot imagine that many people using it for new mobile projects in 2026 (outside of game dev I mean). It’s a very decent language (I mean C#) and runtime, I wish it had more market share in the startup world.

An enterprise shop I co-op'd at was porting one of their apps from Xamarin to MAUI when I worked there, but certainly it doesn't have much mindshare (if any) amongst SE undergrads at my university.
Post reply on HN