M
Marco Segurini
Hi,
I am converting a regular class
enum ENUM_TEST
{
test1,
test2,
test3,
}
class enum_no_generic
{
public static bool IsValid(int id)
{
return System.Enum.IsDefined(typeof(ENUM_TEST), (ENUM_TEST)id);
}
}
in a generic class
class enum_t<T>
{
public static bool IsValid(int id)
{
return System.Enum.IsDefined(typeof(T), (T)id); // line 36
}
}
but I get the following build error:
C:\...\Program.cs(36,50): error CS0030: Cannot convert type 'int' to 'T'
that means that the conversion "(T)id" is not permitted.
Is there any way to achieve my goal?
TIA
Marco.
I am converting a regular class
enum ENUM_TEST
{
test1,
test2,
test3,
}
class enum_no_generic
{
public static bool IsValid(int id)
{
return System.Enum.IsDefined(typeof(ENUM_TEST), (ENUM_TEST)id);
}
}
in a generic class
class enum_t<T>
{
public static bool IsValid(int id)
{
return System.Enum.IsDefined(typeof(T), (T)id); // line 36
}
}
but I get the following build error:
C:\...\Program.cs(36,50): error CS0030: Cannot convert type 'int' to 'T'
that means that the conversion "(T)id" is not permitted.
Is there any way to achieve my goal?
TIA
Marco.