The Color.FromArgb method takes Int32
as a parameter. The value of Color.White is #FFFFFFFF
as ARGB, which is 4.294.967.295
as decimal (way over int.MaxValue
). What am I not understanding here? How can the method take int
as a parameter if valid ARGB values are above the maximum value of an int
?
Unfortunately, since Color.FromArgb takes an int
instead of a uint
, you will need to use the unchecked keyword for colors that are greater than int.MaxValue.
var white = Color.FromArgb(unchecked((int)0xFFFFFFFF));
Your confusion lies in signage. Although Int32.MaxValue is equal to 2,147,483,647, that is signed.
If you look at UInt32.MaxValue, that is unsigned and as you can see, the maximum value is 4,294,967,295.
You see, signed numbers, in binary, use the left most bit to determine if its a positive or negative number. Unsigned numbers, in binary, don't have a signed bit and make use of that last bit, giving you essentially double the storage capacity.
i think part of the reason that the Color
class uses Int32
instead of unsigned is because unsigned int's aren't CLS compliant, as stated in this SO Question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With