Byte occupies less space. If I'm not wrong, an int variable occupies 4 bytes - while a byte variable, well... as the name says, needs only 1 byte.
I thought that we used int because most of the methods out there require arguments of type int, and if we fed them byte type data they'd simply not work.
Well, I tried writing a simple method which requires int numberOne and int numberTwo, returning numberOne + numberTwo. I fed it with two type byte variables - and it worked!
I'm really new to C#, and developing in general - so sorry if there is an obvious answer I know nothing about. Sorry about my English too.
Would be anyone kind enough to explain which are the benefits of using int every time we want to work with an integer data type, even if it's just something that can be saved in within the 0-255 range?
Thanks!
static int Sum(int numberOne, int numberTwo)
{
return numberOne + numberTwo;
}
static void Main(string[] args)
{
byte numberOne = 1, numberTwo = 2;
Console.WriteLine(Sum(numberOne, numberTwo));
}