Premal Mehta

Premal Mehta

  • NA
  • 46
  • 6.1k

Structs cannot contain explicit parameterless constructors

Jun 23 2016 10:43 AM

hi,

I need to implement C++ types in c#. Here's my code.

    [StructLayout(LayoutKind.Sequential)]
    public struct tdUMSFuncValue
    {
        //[FieldOffset(0)]
        [MarshalAs(UnmanagedType.LPTStr)]
        public string szName;

        //[FieldOffset(2)]
        public tdUMSFuncType ft;

        //[FieldOffset(4)]
        public double dfloat;

        //[FieldOffset(6)]
        public int lInteger;

        //[FieldOffset(8)]
        public Int64 time_t;

        //[FieldOffset(10)]
        [MarshalAs(UnmanagedType.LPTStr)]
        public string szString;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct tdUMSFuncValues
    {
        public tdUMSFuncValue[] fv;
        public int lCt;
        public tdUMSFuncValues()
        {
            tdUMSFuncValue[] fv = new tdUMSFuncValue[11];
            fv[0] = new tdUMSFuncValue();
            lCt = 0;
        }
    }

I get this error :
 Structs cannot contain explicit parameterless constructors 
 
How can this be done in C#. I need to use struct at I am replacing a C++ dll with c# dll.
 
any ideas.
 
thanks.
Pr 
 

Answers (2)