c# - 类型必须是不可为空的值

标签 c# unity3d concurrentdictionary

我正在尝试创建类型为 Dictionary 的 NativeArray,但出现此错误:

The type Realtime.Messaging.Internal.ConcurrentDictionary<string,Chunk>' must be a non-nullable value type in order to use it as type parameterT' 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/

相关文章:

c# - 如何让 C# WebSocketClient 持续监听消息

c# - 为什么 C# 使用 [System.Serializable] 来保存实例? (Unity3D)

unity3d - 统一 : how to embed a VR Cardboard game into a website

c# - Microsoft AVRO 是否能够序列化 ConcurrentDictionary?

c# - ConcurrentDictionary.TryUpdate 方法中的 ComparisonValue 参数的原因是什么?

c# - ConcurrentDictionary ContainsKey 方法是否同步?

c# - 如何在最后一个 '.' 值处拆分字符串

c# - 在 WPF/XAML 中,每个容器控件都应该包含一个布局控件吗?

c# - 在 SignalR 中通过 UserId 查找连接

c# - 如何右对齐最后一个 TabControl 选项卡?