Possible Duplicate:
Create Generic method constraining T to an Enum
Is there any reason why we can't do this in C#? And, if possible, how can I do something similar!
What I want :
public class<T> ATag where T : enum {
[Some code ..]
}
public class<T> classBase where T : enum {
public IDictionary<T, string> tags { get; set; }
}
So, when it comes the time to call it, I'm sur to get only one of my enum values.
public class AClassUsingTag : classBase<PossibleTags> {
public void AMethod(){
this.tags.Add(PossibleTags.Tag1, "Hello World!");
this.tags.Add(PossibleTags.Tag2, "Hello Android!");
}
}
public enum PossibleTags {
Tag1, Tag2, Tag3
}
Error message : "Constraint cannot be special class 'System.Enum'"
Thank you!