C# equivalent for kotlin inline classes

Viewed 188
1 Answers

As Hans Passant commented, structs in C# are the equivalent in terms of outcome.

The C# Struct is a value type: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct

A structure type (or struct type) is a value type that can encapsulate data and related functionality.

Being a value type, it is usually added to the stack (except when it's boxed), as the kotlin equivalent.

It does have limitations too (can't extend other structs or classes but can implement interfaces, the constructor must initialize everything etc), but it's much more versatile than the alpha version of inline classes.

Related