I have these two classes:
public class Message
{
string Message;
string Code;
}
public class MessageInitializer
{
DataSet ds;
DataRow dr;
message[] ms;
}
I want to create a constructor in MessageInitializer like this:
MessageInitializer()
{
this.ms = new Message[ds.Tables[0].Rows.Count];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
dr = ds.Tables[0].Rows[i];
ms[(string)dr.ItemArray[0]] = (string)dr.ItemArray[1];
}
}
But array's index must be int type. I have no idea how to work this out:
ms[(string)dr.ItemArray[0]] = (string)dr.ItemArray[1];
Update:
Code format is a string like this: [001-001-001], so I can't convert it to integer.
Integer.parseInt(dr.ItemArray[0])dr.ItemArray[0]is code anddr.ItemArray[1]is message?dr.ItemArray[0]?{001-001-001]?Array<Message>and notDictionary<string, Message>?