Greetings,
I need some help.
In order to save memory space, I would like to perform calculations with the byte data type, instead of int.
The number will never reach beyond 255, and will never be negative...
The problem is described in the code, so please take a look.
If you perhaps have no time to test this out yourself, this is the Error List that Microsoft Visual C# 2010 Express displays:
Any help will be greatly appreciated...
Lovro Mirnik
I need some help.
In order to save memory space, I would like to perform calculations with the byte data type, instead of int.
The number will never reach beyond 255, and will never be negative...
The problem is described in the code, so please take a look.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ByteCalculation
{
class Program
{
static void Main(string[] args)
{
byte Number_1 = 10; // Declaring the value
byte Number_2 = 12; // Declaring the value
Console.WriteLine(Number_1 + Number_2); // Output is 22 - CORRECT!
// ---------------------------------------------------------------
// Here it's where it stops.
// If I wanted to make a basic operation, such as add 1
// I would have to declare 1 as a byte value.
// ???????????????????????????????
Number_1 = Number_1 + 1; // ?????? While, when having an int, this is possible.
// ???????????????????????????????
Console.ReadKey();
// Could there be another solution, which wouldn't require me to declare each value?
}
}
}
Code:
Error 1 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
Lovro Mirnik
Comment