Arrays inside of structs

K

Ken Beauchesne

Can someone help me out as to how to declare the Alarm array

Thanks
Ken


private void button1_Click(object sender, System.EventArgs e)
{
//
DCconfig.Ndata Dc = new DCconfig.Ndata();

Dc.System.ComPorts.Port1.DataBits = 7; // this works

Dc.Alarms.Alarm[0].Channel = 1; // this throws
System.NullReferenceException


}

namespace DCconfig
{
public class Cdata
{
public struct SysT
{
public string ConfigVersion;
public string FirmwareVirsion;
public string RecorderModel;
public string RecorderUnitTag;
public bool Beeper;

public struct ComP
{
public ComPortSpace.ComPorts Port1,Port2, Port3;
}
public ComP ComPorts;
}
public SysT System;
//-------------------------- system
end

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
}
public AlrM Alarms;
//--------------------------- end
alarms

}

public class Ndata
{
public Cdata.SysT System;
public Cdata.AlrM Alarms;
}

}


//----------------------------------------------
namespace AlarmSpace
{

public struct AlarmData
{
public bool Enable;
public bool Notify;
public byte Channel;
public string Type;
public float SetPoint;
public float DeadBand;
public uint Delay;
public uint Contact;
public struct EvntM
{
public bool Enable;
public string Message;
}
public EvntM EventMsg;

}

}
 
S

Sam Sungshik Kong

Ken,

You declared a reference of an array but didn't create the array itself.

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
public AlrM(int num)
{
Alarm = new AlarmSpace.AlarmData[num];
}
}

Hope this helps..

Sam
 
K

Ken Beauchesne

Thanks

Ken
Sam Sungshik Kong said:
Ken,

You declared a reference of an array but didn't create the array itself.

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
public AlrM(int num)
{
Alarm = new AlarmSpace.AlarmData[num];
}
}

Hope this helps..

Sam

Ken Beauchesne said:
Can someone help me out as to how to declare the Alarm array

Thanks
Ken


private void button1_Click(object sender, System.EventArgs e)
{
//
DCconfig.Ndata Dc = new DCconfig.Ndata();

Dc.System.ComPorts.Port1.DataBits = 7; // this works

Dc.Alarms.Alarm[0].Channel = 1; // this throws
System.NullReferenceException


}

namespace DCconfig
{
public class Cdata
{
public struct SysT
{
public string ConfigVersion;
public string FirmwareVirsion;
public string RecorderModel;
public string RecorderUnitTag;
public bool Beeper;

public struct ComP
{
public ComPortSpace.ComPorts Port1,Port2, Port3;
}
public ComP ComPorts;
}
public SysT System;
//-------------------------- system
end

public struct AlrM
{
public AlarmSpace.AlarmData [] Alarm ;
}
public AlrM Alarms;
//--------------------------- end
alarms

}

public class Ndata
{
public Cdata.SysT System;
public Cdata.AlrM Alarms;
}

}


//----------------------------------------------
namespace AlarmSpace
{

public struct AlarmData
{
public bool Enable;
public bool Notify;
public byte Channel;
public string Type;
public float SetPoint;
public float DeadBand;
public uint Delay;
public uint Contact;
public struct EvntM
{
public bool Enable;
public string Message;
}
public EvntM EventMsg;

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top