tags:

views:

89

answers:

2

Hello, a few months ago I wrote this code because it was the only way I could think to do it(while learning C#), well. How would you do it? Is unchecked the proper way of doing this?

unchecked //FromArgb takes a 32 bit value, though says it's signed. Which colors shouldn't be.
{
  _EditControl.BackColor = System.Drawing.Color.FromArgb((int)0xFFCCCCCC);
}
+6  A: 

It takes a signed int b/c this dates back to the time when VB.NET didn't have unsigned values. So in order to maintain compatibility between C# and VB.NET, all the BCL libraries utilize signed values, even if it does not make logical sense.

Nick
+1 for historical insight.
Steven Sudit
Another way to look at this is that CLS-compliant languages are not required to understand uint. So the libraries generally avoid uint.
Eric Lippert
Other classes (like `System.Net.IPAddress`) decided to use the larger signed 64-bit type so people could more easily pass in a full 32-bit unsigned value to get around this issue.
Michael Burr
+2  A: 

You could break down the components of the int and use the FromArgb() overload that takes them separately:

System.Drawing.Color.FromArgb( 0xFF, 0xCC, 0xCC, 0xCC);
Michael Burr