I am fairly new to C# and I have having problems with adding an object to a class inside a class. It keeps telling me to "Use the 'new' keyword to create an object instance".
Here is my class:
public class Info
{
public List<SourceInfo> sourceInfo { get; set; }
}
public class SourceInfo
{
public short id { get; set; }
public string name { get; set; }
public string icon { get; set; }
public short subpage { get; set; }
public short xpoint { get; set; }
public short mediaPlayerId { get; set; }
public SourceInfo(short ID, string NAME, string ICON, short SUBPAGE, short XPOINT, short MEDIAPLAYERID)
{
id = ID;
name = NAME;
icon = ICON;
subpage = SUBPAGE;
xpoint = XPOINT;
mediaPlayerId = MEDIAPLAYERID;
}
Here is my code:
Info configSelect = new Info();
private void btnSave_Click(object sender, EventArgs e)
{
try
{
configSelect.sourceInfo.Add (new SourceInfo(Convert.ToInt16(txtSrcId.Text),
txtSrcName.Text, txtSrcIcon.Text, Convert.ToInt16(txtSrcSubpage.Text),
Convert.ToInt16(txtSrcXpoint.Text), Convert.ToInt16(txtSrcMPId.Text)));
WriteFile(configSelect);
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}