gpt4 book ai didi

c# - 结构中的结构数组

转载 作者:行者123 更新时间:2023-11-30 22:29:07 25 4
gpt4 key购买 nike

是否可以在另一个struct中声明struct数组字段?

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct A
{
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct B
{
public fixed A FieldA[123];
}

Visual Studio 告诉 FieldA 只能是任何简单类型的数组,而不是 struct。这里有任何解决方案/解决方法吗?

最佳答案

Is it possible to declare struct array field in another struct?

是的,但是如果你想把它做成一个固定大小的缓冲区是有限制的。来自 C# 4 规范的第 18.7.1 节:

The buffer element type of a fixed size buffer declaration specifies the element type of the buffer(s) introduced by the declaration. The buffer element type must be one of the predefined types sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, or bool.

我不知道有任何替代方法可以模拟任意结构的固定大小的缓冲区。

关于c# - 结构中的结构数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10361211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com