I keep getting this error on the second prepopulated… Cannot implicity convert type string to System.Collections.Generic.IEnumerable and I am unsure of what I am doing wrong.
namespace HomeInventory2
{
public partial class Form1 : Form
{
public Form1(string prepopulated)
{
InitializeComponent();
IEnumerable<String> lines = prepopulated;
textBoxAmount.Text = lines.ElementAtOrDefault(0);
textBoxCategories.Text = lines.ElementAtOrDefault(1);
textBoxProperties.Text = lines.ElementAtOrDefault(2);
textBoxValue.Text = lines.ElementAtOrDefault(3);
}
private void label1_Click(object sender, EventArgs e)
{
}
private void submitButton_Click(object sender, EventArgs e)
{
CreateInventory create = new CreateInventory();
create.ItemAmount = textBoxAmount.Text;
create.ItemCategory = textBoxCategories.Text;
create.ItemProperties = textBoxValue.Text;
create.ItemValue = textBoxValue.Text;
InventoryMngr invtryMngr = new InventoryMngr();
invtryMngr.Create(create);
}
}
You have your constructor taking a single string as a parameter:
You then are trying to set this to an
IEnumerable<string>:You need to, instead, pass in an
IEnumerable<string>:If your
prepopulatedstring is a string which can be parsed into multiple strings, you could do that instead. For example, if it’s “prepopulated” with a string with newline separations, you could instead do something like: