Why int is a struct in C#? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why int is a struct in C#?

Why int is a struct in C#?

22nd Feb 2018, 12:32 PM
Rachid Antunes
Rachid Antunes - avatar
3 Answers
+ 3
We know that int has a maximum and a minimum value, on the other hand though a string can grow dynamically, it doesn't have an exact size like int has, I'm gonna elaborate this in another comment.
22nd Feb 2018, 1:02 PM
Kevin Eldurson
Kevin Eldurson - avatar
+ 3
So the size of an unassigned integer (uint) by default is 32 bit. That literally means 32 pieces of the number 1 next to each other in binary: 111111111111111111111111111111111 This is 4294967295 in binary (2^32-1). Why minus one? Because we don't count from one but from zero, thus we don't actually count zero.
22nd Feb 2018, 1:10 PM
Kevin Eldurson
Kevin Eldurson - avatar
+ 3
So eventually uint can store 2^32 values but the max value is 2^32-1 because we start counting from zero.
22nd Feb 2018, 1:12 PM
Kevin Eldurson
Kevin Eldurson - avatar