Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot implicitly convert type string

Tags:

c#

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);

        }
    }
like image 626
Expecto Avatar asked Aug 23 '26 08:08

Expecto


1 Answers

This line

IEnumerable<String> lines = prepopulated;

prepopulated is a string and you are trying to assign it to a List of strings. Maybe you want to Split() it first? Or maybe your Form's constructor should take a List of strings to begin with.

like image 167
Dharun Avatar answered Aug 25 '26 22:08

Dharun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!