I am sorry for the weird title but I coulnt figure out how to express it :) I recently shifted to C# and currently I am working on structures. I am basically a C++ developer and in my c++ code I had done the folowing:
typedef struct
{
String ChannelName;
bool available;
} Voltage_Channel;
Voltage_Channel *m_voltageChannels;
Voltage_Channel redhookChannels[6] = {
{"", false},
{"VDD_IO_AUD", true},
{"VDD_CODEC_AUD",true},
{"VDD_DAL_AUD", true},
{"VDD_DPD_AUD", true},
{"VDD_PLL_AUD", true}
};
if(m_boardName->compareIgnoreCase("S1010012") == 0) //m_BoardName is string
{
m_voltageChannels = redhookChannels;
}
I need to do this in my c# application. I tried it as follows but something is wrong:
struct VoltageBoardChannel
{
public string ChannelName;
public bool available;
};
VoltageBoardChannel[] mVoltageStruct;
VoltageBoardChannel[] redhookChannels = new VoltageBoardChannel[6]
{
new VoltageBoardChannel() { ChannelName = "", available = false},
new VoltageBoardChannel() { ChannelName = "VDD_IO_AUD", available = true},
new VoltageBoardChannel() { ChannelName = "VDD_CODEC_AUD", available = true},
new VoltageBoardChannel() { ChannelName = "VDD_DAL_AUD", available = true},
new VoltageBoardChannel() { ChannelName = "VDD_DPD_AUD", available = true},
new VoltageBoardChannel() { ChannelName = "VDD_PLL_AUD", available = true}
};
string redhookboardname = "S1010012";
string redhookboardnameCase = "s1010012";
if (redhookboardnameCase.Equals(redhookboardname, stringComparison.InvariantCultureIgnoreCase))
{
mVoltageStruct = redhookChannels;
}
Where Am I making a mistake??? :(
mVoltageStruct? do you want to assign the first item of your arrayredhookChannels?mVoltageStructm_voltageChannelsis a pointer to the first item in the array, but that isn't copying anything.redhookChannelsis an array, in your C++ code you are assigning it to a pointer of the struct type, In C# you have define another array and make copy of it.