Create List object from another List using C# and VB.Net in WPF Application

Last Reply on Dec 06, 2018 12:34 AM By pandeyism

Posted on Dec 05, 2018 11:16 PM

Hi everyone,

I have a C# WPF window that I insert 4 List<T> a string,decimal,decimal, and int. Each list is numbered correctly 0,1,2… with the correct information in order in the list.

I am trying to create a public property of a List<myobject> that has properties myobject.string, myobject.decimal, myobject.decimal, myobject.int

How can I enter these properties into my list of my object? Here is what I have and some ways I have been trying.

    public partial class ShoppingCart : Window
    {
        private List<string> listProductNames = new List<string>();
        private List<decimal> listProductPrices = new List<decimal>();
        private List<decimal> listProductSalesTax = new List<decimal>();
        private List<int> listProductQuantity = new List<int>();
        public List<Product> Cart => new List<Product>();

        public ShoppingCart(Customer c, List<string> lpn, List<decimal> lpp, List<decimal> lpt, List<int> lpq)
        {
            InitializeComponent();
            customer = c;
            listProductNames = lpn;
            listProductPrices = lpp;
            listProductSalesTax = lpt;
            listProductQuantity = lpq;
            CreateCart(listProductNames, listProductPrices, listProductSalesTax, listProductQuantity);
            PopulateListViewCart();
        }

        private void CreateCart(List<string> lpn, List<decimal> lpp, List<decimal> lpt, List<int> lpq)
        {
            selectedProduct = new Product();

            foreach(string name in lpn)
            {
                selectedProduct.ProductName = name;
            }
            foreach(decimal price in lpp)
            {
                selectedProduct.ProductPrice = price;
            }
            foreach(decimal tax in lpt)
            {
                selectedProduct.ProductTax = tax;
            }
            foreach(int quantity in lpq)
            {
                selectedProduct.ProductQuantity = quantity;
            }
            Cart.Add(selectedProduct);
        }
    }

 

This question does not have replies that have been liked.