C# – Enum with default typecast? is that possible


is it possible to make a default typecast for an enum?

I use enum for a lot, such as states and I want to compare enums directly to LINQ fields, but I have to typecast all the time.

Best Solution

You should be able to have properties in your LINQ objects that have an enum type. This way you do not have to cast.

So just change your properties to have the correct enum type and you don't have to worry about casts any longer. You can do this in the LINQtoSQL designer. Just right-click on a property, select 'Properties' and set the appropriate Type in the Visual Studio Properties window.