I am new to C#. I am trying to complile the following program but it throws an error given at the end: I know I am making a silly mistake. Any help would be much appreciated:
static void Main(string[] args) {
IntPtr hCannedMessages = CannedMessagesInit();
using (StreamReader sr = new StreamReader(CANNED_MESSAGE_FILE))
{
String line, sub;
all_integer_IDs[] myobjarray;// = new all_integer_IDs[10];
for (int c = 0; c < 10; c++)
{
myobjarray[c] = new all_integer_IDs();
}
line = sr.ReadLine();
Console.WriteLine(line);
if (line.Length > 15)
{
sub = line.Remove(line.IndexOf(' ', 2));
Console.WriteLine("{0} \n",sub);
myobjarray[0].setvalues((int)sub[2], (int)sub[3], (int)sub[4], (int)sub[5]);
Console.WriteLine("{0}, {1}, {2}, {3}", myobjarray[0].m_messageID, myobjarray[0].m_messagetype, myobjarray[0].m_classID, myobjarray[0].m_categoryID); }
Console.Read();
sr.Close();
}
}
}
}
And the class is in Class1.cs file in the same project and is as follows:
public class all_integer_IDs {
public all_integer_IDs()
{
setvalues(0, 0, 0, 0);
}
~all_integer_IDs()
{
}
public void setvalues (int messageID, int messagetype, int classID, int categoryID)
{
this.m_messageID = messageID;
this.m_messagetype = messagetype;
this.m_classID = classID;
this.m_categoryID = categoryID;
}
public int m_messageID;
public int m_messagetype;
public int m_classID;
public int m_categoryID;
}
The error is as follows: Use of unassigned local variable 'myobjarray' at line 55 which is copied and pasted below: myobjarray[c] = new all_integer_IDs();
Thanks, Viren