Inconveniences of Unsigned Types in .NET
Languages like C++ come with convenient support for unsigned integer types where
non-negative values make sense. std::size_t is the unsigned integer type of
the sizeof and alignof operators. std::size_t is also used when indexing
C++ containers.
In contrast, .NET tends to use signed integer types even where unsigned ones would be more intuitive, e.g.,
.NET is language independent. Languages like C#, F#, and Visual Basic target
.NET implementations. The Common Language Specification (CLS) is the set of
features that are common to all the languages. Of relevance is the fact that
Byte, Int16, Int32, and Int64 are the only CLS-compliant integer types.
References
- std::size_t - cppreference.com. en.cppreference.com . Accessed Jan 2, 2026.
https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.count?view=net-10.0
- List<T>.Count Property (System.Collections.Generic) | Microsoft Learn. learn.microsoft.com . Accessed Jan 2, 2026.
- List<T>.Item[Int32] Property (System.Collections.Generic) | Microsoft Learn. learn.microsoft.com . Accessed Jan 2, 2026.
- Language independence and language-independent components - .NET | Microsoft Learn. learn.microsoft.com . Accessed Jan 2, 2026.
- c# - Signed vs. unsigned integers for lengths/counts - Stack Overflow. stackoverflow.com . Accessed Jan 2, 2026.
- Enumerable.Sum Method (System.Linq) | Microsoft Learn. learn.microsoft.com . Accessed Jan 2, 2026.
The use of signed integer types over unsigned ones also appears in other areas like LINQ helpers, e.g.,
Enumerable.Sumhas overloads forInt32andInt64but not the unsigned versions.