这个功能在实际项目中有啥用,我也不知道,先记录下来。
class Program
{
static void Main(string[] args)
{
unsafe//在不安全的代码下,才能使用sizeof,检查自定义结构体所占的内存
{
int x = sizeof(Student);//检查结构体所占的内存
Console.WriteLine(x);
}
}
}
struct Student
{
int ID;
long Score;
}
使用不安全的代码时,需要在生成中设置允许不安全代码。