我正在尝试创建一个字典类型的NativeArray,并得到了以下错误:
泛型类型或方法
Realtime.Messaging.Internal.ConcurrentDictionary<string,Chunk>' must be a non-nullable value type in order to use it as type parameter‘中的Realtime.Messaging.Internal.ConcurrentDictionary<string,Chunk>' must be a non-nullable value type in order to use it as type parameterT’类型
NativeArray<ConcurrentDictionary<string, Chunk>> dictionary = new NativeArray<ConcurrentDictionary<string, Chunk>>(8, Allocator.TempJob);我是团结和C#的新手,这个问题可能是以前问过的,但我一直在寻找修复方法,却什么也找不到。
我怎么才能解决这个问题?
发布于 2018-07-18 19:43:45
答案是在您收到的错误消息中:.必须是非空值类型.ConcurrentDictionary是一个引用类型,NativeArray似乎有一个类型参数约束,只能接受结构,这种约束类型如下:
class Foo<T> where T:struct{}这意味着您只能创建值类型(结构):int、NativeArray、char、...etc或您自己的结构.
https://stackoverflow.com/questions/51409682
复制相似问题