0

I'm currently working on a Project with Images. I've tested one Image in CMYK-Format, and one in RGB. Both are Bitmaps. Bitmaps have the Property "PixelFormat". It's an Enum, where the Values are:

0 Undefined
0 DontCare (Yes, it's C# Basic btw, not any third library..)
15 Max
Indexed 65536

... The other values are way above those numbers.

If i read the PixelFormat of the RGB-Bitmap, it returns "PixelFormat.Format24bppRgb". That's like it's supposed to be.

If i read the PixelFormat of the CMYK-Bitmap, it returns the value 8207.

8207 is not implemented in the Enum, but it gets returned anyways. I found a workaround to forget about this fact, but it still lets me wonder about that.

Following Code is WORKING:

public static Test testProperty
{
    get { return (Test) 691337; }
}
public enum Test
{
    FirstValue=0,
    SecondValue = 24
}

So like the title says:

Why can i cast an enum into a value, that is not defined in the enum-Body?

Schrank97
  • 13
  • 2
  • 1
    Consider it like enums are just a thing to help you code with names, rather than magic numbers.. but under the hood they're just translated to magic numbers, which are no more or less valid than any other number – Caius Jard Mar 04 '21 at 07:19
  • You can do it because someone on the .NET / compiler team decided that it was OK. – Lasse V. Karlsen Mar 04 '21 at 08:44

0 Answers0