C# 编码(marshal).SizeOf

标签 c# size marshalling

我正在使用 Marshal.SizeOf 来了解我的结构的大小:

struct loginStruct
{
    public string userName;
    public string password;

    public loginStruct(string userName, string password)
    {
        this.userName = userName;
        this.password = password;
    }
}

下面是这个函数的使用:

int len = Marshal.SizeOf(typeof(loginStruct));

我有 2 个程序。在一个程序中,len 等于 8。在另一个程序中,它等于 16。 它是相同的结构。为什么我有这种差异?

最佳答案

我猜一个程序是为 AnyCPU 编译的(在 64 位平台上将是 64 位),另一个程序是为 32 位编译的。

关于C# 编码(marshal).SizeOf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20003436/

相关文章:

c# - 什么时候不要使用 'this' 关键字?

c# - 对 ASP.NET 中进一步包含对象的对象列表进行排序

c# - 在 C# 中编码(marshal) ushort[,] 多维数组

java - 通过@ResponseBody 返回时更改 DTO JSON 中的日期格式

C - 使用 htonl 和 ntohl 编码/取消编码结构

c# TDD 第一次出现在 ServiceBase 中

c# - List<string> 和 IEnumerable<String> 有什么区别?

Android:在不同的屏幕密度上绘制相同尺寸的直线或圆圈

javascript - 如何设置 twitter bootstrap 模式更宽更高?

android - 如何在 android studio 中缩放字体大小?