我正在尝试创建类型为 Dictionary 的 NativeArray,但出现此错误:
The type
Realtime.Messaging.Internal.ConcurrentDictionary<string,Chunk>' must be a non-nullable value type in order to use it as type parameter
T' in the generic type or method `Unity.Collections.NativeArray'
NativeArray<ConcurrentDictionary<string, Chunk>> dictionary = new NativeArray<ConcurrentDictionary<string, Chunk>>(8, Allocator.TempJob);
我是 Unity 和 C# 的新手,之前可能有人问过这个问题,但我一直在寻找修复方法,但找不到任何东西。
我该如何解决这个问题?
最佳答案
答案在你得到的错误消息中:.. must be a non-nullable value type... ConcurrentDictionary 是一个引用类型,NativeArray 似乎有一个类型参数约束来接受只有结构,约束类型如下:
class Foo<T> where T:struct{}
这意味着您只能创建值类型(结构)的 NativeArray:int、byte、char 等,或您自己的结构...
关于c# - 类型必须是不可为空的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51409682/