Linked Questions

97 votes
12 answers
24k views

What I want to do is something like this: I have enums with combined flagged values. public static class EnumExtension { public static bool IsSet<T>( this T input, T matchTo ) ...
Keith's user avatar
  • 157k
38 votes
2 answers
56k views

Possible Duplicate: Enum type constraints in C# Is it possible to use enum types as a generic paramter by using its wrapper class Enum? I have different enums: enum errors1 { E1, E3, E8 }; enum ...
Konrad Reiche's user avatar
2 votes
1 answer
4k views

Possible Duplicate: Create Generic method constraining T to an Enum Enum type constraints in C# Consider the following class: public class Transition<TState> { public Transition () ...
Raheel Khan's user avatar
  • 14.8k
1 vote
1 answer
1k views

Possible Duplicate: Enum type constraints in C# Could somebody kindly explain to me with a simple sample and simple words why enum constraints are not allowed on a generic type i.e. What would ...
Idrees's user avatar
  • 863
972 votes
319 answers
504k views

What is, in your opinion, the most surprising, weird, strange or really "WTF" language feature you have encountered? Please only one feature per answer.
141 votes
10 answers
51k views

Similar to Cast int to enum in C# but my enum is a Generic Type parameter. What is the best way to handle this? Example: private T ConvertEnum<T>(int i) where T : struct, IConvertible { ...
csauve's user avatar
  • 6,343
49 votes
3 answers
34k views

I'm writing an utility function that gets a integer from the database and returns a typed enum to the application. Here is what I tried to do (note I pass in a data reader and column name instead of ...
Justin's user avatar
  • 10.9k
23 votes
8 answers
24k views

Possible Duplicate: C# generic constraint for only integers Greets! I'm attempting to set up a Cartesian coordinate system in C#, but I don't want to restrict myself to any one numerical type for ...
Syndog's user avatar
  • 1,687
29 votes
2 answers
5k views

... with all those new (and not so new if we count IEnumerable) monad-related stuff? interface IMonad<T> { SelectMany/Bind(); Return/Unit(); } That would allow to write functions that ...
UserControl's user avatar
  • 15.3k
19 votes
5 answers
17k views

Say I have an enum something like: enum OrderStatus { AwaitingAuthorization, InProduction, AwaitingDespatch } I've also created an extension method on my enum to tidy up the displayed ...
fearofawhackplanet's user avatar
11 votes
4 answers
4k views

Update: See the bottom of this question for a C# workaround. Hi there, Consider the following extension method: public static bool HasFlags<T>(this T value, T flags) where T : System.Enum { ...
Blixt's user avatar
  • 50.3k
9 votes
4 answers
623 views

First things off, I had no idea what to title this question - I'm even confused how to state it. Now for the question. Let's take the System.IO.FileSystemWatcher class where you set it's ...
Eon's user avatar
  • 3,994
8 votes
1 answer
7k views

How do I convert from enums to strings and vice versa? And taking the case that enums can contain multiple flags, how can I get a list of all the flags an enum contains?
Ahmed Fwela's user avatar
4 votes
2 answers
10k views

I would like to declare in a parent abstract class something along the lines of: public abstract void RefreshDisplay<TView>(Enum value); Which would then be implemented in the child class ...
Alan Wayne's user avatar
  • 5,424
3 votes
2 answers
7k views

I would like to have a method that will parse from a nullable database column an enum. I wrote this method below (and had to restrict T to a struct to make it compile). It does compile, but I believe ...
M Afifi's user avatar
  • 4,815

15 30 50 per page