I have been writing a rather low level application in C# that uses a lot of bytes shorts and bit manipulation. One thing I noticed is that C# doesn't like to do bit manipulation and use boolean operators on anything other than ints. This has resulted in 100's of casts all over my code. Errors such as "Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?)"
byte b1 = 0x22;
byte b2 = 0x33;
ushort s1 = b1 << 8; // <-- Error Here
ushort s2 = s1 | b2; // <-- And Here
This forces me to use casts everywhere.
byte b1 = 0x22;
byte b2 = 0x33;
ushort s1 = (ushort)(b1 << 8 | b2);
This should at most be a warning. Even if b1 and b2 where of type ushort it is still an error. Even basic arithmetic such as addition gives the same error.
ushort s1 = 0x22;
ushort s2 = s1 + 0x11; // <-- Oh Come On.
ushort s3 = 8;
ushort s4 = (s1 << s3 | s2); // <-- Still an Error.
Is there anyway around this or do I just have to resign myself to the fact that casts are just a part of C# life when it comes to using anything other than integers or just use C++ where this is not a problem.