110,556
社区成员
发帖
与我相关
我的任务
分享
struct stru_test
{
int arrNumber[10];
}
struct stru_use
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
public GLOBAL_WAYPOINT[] globalWaypoint;
};
struct stru_test
{
public fixed int arrNumber[10];
}
http://msdn.microsoft.com/zh-cn/library/zycewsya.aspx
public class Student
{
public int[6] Scores { get; set; }
}
Student aaa = new Student();
aaa.Scores = new int[] { 1, 2, 3, 4, 5, 6 };
Console.WriteLine(string.Join(" ", aaa.Scores));
如果试图赋值超过限定量则提示错误。
struct GLOBAL_WAYPOINT
{
int a;
int b;
int c;
short d;
short e;
short f;
short g;
};
struct stru_use
{
// 编译时提示固定大小的缓冲区类型必须为基础数据类型
public unsafe fixed GLOBAL_WAYPOINT globalWaypoint[100];
};
[/quote]
我的错,确实不行,看来我想多了
在 C# 中,可以使用 fixed 语句在数据结构中创建带有固定大小数组的缓冲区。 使用现有代码(如使用其他语言、预先存在的 DLL 或 COM 项目编写的代码)时,这种方法非常有用。 固定数组可采用允许普通结构成员使用的任何特性或修饰符。 唯一的限制是,数组类型必须是 bool、byte、 char、 short、int、long、sbyte、ushort、uint、ulong、float 或 double。
struct GLOBAL_WAYPOINT
{
int a;
int b;
int c;
short d;
short e;
short f;
short g;
};
struct stru_use
{
// 编译时提示固定大小的缓冲区类型必须为基础数据类型
public unsafe fixed GLOBAL_WAYPOINT globalWaypoint[100];
};