余道长
2018-02-01 07:41
采纳率: 52.9%
浏览 1.2k

急!急!急! C++ 结构体带构造函数的在C#中改如何定义

struct THFI_Param
{
int nMinFaceSize;
int nRollAngle;
bool bOnlyDetect;
DWORD dwReserved;
THFI_Param()
{
nMinFaceSize=50;
nRollAngle=30;
bOnlyDetect=false;
dwReserved=NULL;
}
};

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • psychopiz 2018-02-02 00:39
    已采纳
    public class THFI_Param {
    public int nMinFaceSize { get; set; }
    public int nRollAngle { get; set; }
    public bool bOnlyDetect { get; set; }
    public uint? dwReserved { get; set; }
    public THFI_Param() {
            this.nMinFaceSize = 50;
                this.nRollAngle = 30;
                this.bOnlyDetect = false;
                this.dwReserved = null;
        }
    }
    
    点赞 打赏 评论
  • youke568 2018-02-01 08:21

    struct 改 class
    属性前加 public

    点赞 打赏 评论
  • kongrenxin 2018-02-01 08:23

    直接改成你的C#类不就完了?

     class THFI_Param
    {
        int nMinFaceSize;
        int nRollAngle;
        bool bOnlyDetect;
        DWORD dwReserved;
        public THFI_Param()
        {
            nMinFaceSize = 50;
            nRollAngle = 30;
            bOnlyDetect = false;
            dwReserved = NULL;
        }
    };
    
    点赞 打赏 评论
  • sky_zytian 2018-02-01 08:28

    把struct理解为类,在C#中定义定义就可以

    点赞 打赏 评论
  • 有点贪玩 2018-02-01 09:06

    其实在c++本身,你也可以吧struct当做类理解,一般struct是用于纯数据(不会带其他的一些操作函数)
    c#语法上和c++比较类似

    点赞 打赏 评论
  • Antony_WU_SZ 2018-02-02 08:15

    [StructLayout(LayoutKind.Sequential)]
    public struct ControllerState
    {
    // Common
    public int handle;
    public int timestamp;
    public int frameCount;
    public int state_mask;
    // Gamepad
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
    public float[] axes;
    public int buttons;
    // Motion
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
    public float[] position;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
    public float[] rotation;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
    public float[] accelerometer;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
    public float[] gyroscope;
    }

                对照下以上的
    
    点赞 打赏 评论

相关推荐 更多相似问题