Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET enum size?

Tags:

.net

enums

How many entries can an enum in .NET have?

like image 546
Brian Webster Avatar asked Nov 28 '22 15:11

Brian Webster


1 Answers

I'm pretty certain the underlying type is an integer type (not necessarily an int). This page here states that:

The approved types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong. The underlying type specifies how much storage is allocated for each enumerator.

and:

Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time.

So I would suggest the only limitation will be the range of long/ulong (well into the billions) and the allowable symbol space in the compiler for enumerations (you'll most likely strike that limitation first if you're actually creating truly massive enumerations).

If you specify a smaller type for your enumeration (e.g., short), the range will be reduced accordingly.

like image 56
paxdiablo Avatar answered Dec 04 '22 16:12

paxdiablo