Search code examples
c#unchecked

How to do this without unchecked?


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);
}

Solution

  • 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);