默认情况下,泛型类型? [英] Default for generic type?
本文介绍了默认情况下,泛型类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能做这样的事情。
Is it possible to do something like
public class PriorityQueue<TValue, TPriority=int> where TPriority : IComparable
(注意 = 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.
推荐答案
没有。没有为泛型类型在C#中的默认类型的选项。
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.
这篇关于默认情况下,泛型类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文