
internal class TrIENode<E>{ Nullable<E> Data; string Key; List<TrIENode<E>> Children; public TrIENode(E? data,string key) { Data = data; Key = key; Children = new List<TrIENode<E>>(); }} 在编译时我得到以下错误消息:
The type ‘E’ must be a non-nullable value type in order to use it as parameter ‘T’ in the generic type or method ‘System.Nullable’
有没有办法保证E是一个不可为空的类型,或者其他方式?
解决方法 您只需要:internal class TrIENode<E> where E : struct
:struct子句将E限制为除Nullable<>之外的值类型,它允许Nullable< E>.还是E?工作正常.
总结以上是内存溢出为你收集整理的c# – Nullable和泛型全部内容,希望文章能够帮你解决c# – Nullable和泛型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)