Cannot implicitly convert type 'long' to 'uint'

jdy0803

Member
Joined
May 20, 2013
Messages
17
Programming Experience
10+
I comppile this code, error occurs.
uint IMGWIDTH = 100;
uint BitmapByteCountPerLine;

BitmapByteCountPerLine = (IMGWIDTH * 3 + 3) & (~3);<=== Compile Error

Cannot implicitly convert type 'long' to 'uint'. An explicit conversion exists (are you missing a cast?)
this code was came from my C++ code and no error occurred in VC++ 6.0 compiler.
DWORD IMGWIDTH = 100;
DWORD BitmapByteCountPerLine;

BitmapByteCountPerLine = (IMGWIDTH * 3 + 3) & (~3);
 
I converted like this and removed error.

BitmapByteCountPerLine = (uint)((IMGWIDTH * 3 + 3) & (~3));

It seems C# type conversion is more strict than C++.
 
Back
Top Bottom