Why does Windows Forms Designer use int for byte and then back to int for FromArgb?

I was looking at the code today and saw something like the following:

var colour = Color.FromArgb(((int)(((byte)(227)))), ((int)(((byte)(213)))), ((int)(((byte)(193)))));

When I asked why this was so, as Resharper confirmed that all throws were redundant, I was told that the Designer did it this way and they copied it.

I looked and I am sure that the constructor generates the code in the same way as above, when setting the property in a custom color.

Does anyone know why a designer will do this? It seems that it does not make sense at first glance if I am missing something?

+5
source share
2 answers

, Winforms. System.Drawing.ColorConverter, TypeConverter for Color. ConvertTo():

   member = typeof(Color).GetMethod("FromArgb", new Type[] { typeof(int), typeof(int), typeof(int) });
   arguments = new object[] { color2.R, color2.G, color2.B };

R, G B . (byte) cast . , FromArgb() , (int) cast.

, . , .

+9

. , , .

var colour = Color.FromArgb(227, 213, 193);

-:

var colour = Color.FromArgb(255, 227, 213, 193);

@Alexei Levenkov, , , , ( ) , - , 255 ?

Ref. Color.FromArgb

+5

All Articles