83

Is it possible to do something like

public class PriorityQueue<TValue, TPriority=int> where TPriority : IComparable

(note the =int) ?

Before you suggest it, yes, I know I can just add another line:

public class PriorityQueue<TValue> : PriorityQueue<TValue, int> { }

But I'm wondering if it's possible to do it as a param.

ricksmt
  • 888
  • 2
  • 13
  • 34
mpen
  • 272,448
  • 266
  • 850
  • 1,236

1 Answers1

56

No. There is no option for default types on generic types in C#.

Your second example is often the "best" option available, if you need this behavior.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373