struct ATTGUARDCARD
{
int nFileSort;
int nCardID;
char strPersonID[7];
int nGrade, nAttGroup;
char strUserKey[4];
char strName[8];
int nYear, nMonth, nDay;
}
---------------------------(上面是c++)
c#怎么写

解决方案 »

  1.   

    本帖最后由 bdmh 于 2011-09-16 17:15:22 编辑
      

  2.   

    struct ATTGUARDCARD
    {
    int nFileSort;
    int nCardID;
    string strPersonID;
    int nGrade, nAttGroup;
    string  strUserKey;
    string  strName;
    datetime nYear, nMonth, nDay;
    }
    限定的长度再通过string.length 控制
      

  3.   

    struct ATTGUARDCARD
    {
    int nFileSort;
    int nCardID;
    string strPersonID;
    int nGrade, nAttGroup;
    string strUserKey;
    string strName;
    int nYear, nMonth, nDay;
    }
      

  4.   

    2楼的有问题,正确对应如下:  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
      public struct MQTTC_Message
      {
         public int    nFileSort;
         public int    nCardID;
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
         public string strPersonID;
         public int    nGrade;
         public int    nAttGroup;
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
         public string strUserKey;
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
         public string strName;
         public int    nYear;
         public int    nMonth;
         public int    nDay;
       }