using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;namespace Console_File
{
class Program
{
static void Main(string[] args)
{
Info o = new Info();
int buff_size = 0;
int a = Marshal.SizeOf(o.A);
int b = Marshal.SizeOf(o.B);
int c = Marshal.SizeOf(o.C);
int d = SizeOf(bool);
buff_size = a + b + c;
Console.WriteLine("int Marshal.SizeOf:" + a);
Console.WriteLine("bool Marshal.SizeOf:" + b);
Console.WriteLine(c);
Console.WriteLine(buff_size);
Console.WriteLine("bool SizeOf:" + d);
// 要用此方法创建文件
//FileStream fs = new FileStream(filename, mode, access, share, 1, options);
Console.Read();
} private class Info
{
public int A;
public bool B;
public Object C;
}
}
}
现在的问题是,这个类中有Object,这个是不能确定大小的,因为要写入文本,这个类的大小如何确定?
还有就是,Marshal.SizeOf 和 SizeOf 的区别是什么,为什么同样是bool类型,一个大小是4,一个大小是1 ?
请教各位老师多多指点。c# 类中有Object大小问题
我不理解的是 Marshal.SizeOf 和 SizeOf
他两表示的bool 前者是4,后者是1。
我就不明白了;.....