Skip to content

Instantly share code, notes, and snippets.

@kavika13
Created September 15, 2012 05:18
Show Gist options
  • Save kavika13/3726434 to your computer and use it in GitHub Desktop.
Save kavika13/3726434 to your computer and use it in GitHub Desktop.
Enum with base type counter-example
using System;
static class Program
{
public static void Test<TEnum>()
where TEnum : struct
{
Console.WriteLine(typeof(TEnum).IsEnum);
}
public static void Test<TEnum>(this string text)
where TEnum : struct
{
if (!typeof(TEnum).IsEnum)
{
Console.WriteLine("Not an enum");
return;
}
Console.WriteLine("Is an enum");
}
public enum Test1
{
Value1,
Value2,
}
public enum Test2 : byte
{
Value3,
Value4,
}
static void Main(string[] args)
{
Test<Test1>();
Test<Test2>();
"".Test<Test1>();
"".Test<Test2>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment