pass value from list

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Linq;

namespace SalesTaxTest
{
    class Program
    {
        public class Product
        {
            public double Qty { get; set; }
            public string Name { get; set; }
			public double Price { get; set; }
			public double Tax { get; set; }
			
            public Product(int qty, string name, double price, double tax)
            {
                this.Qty = qty;
                this.Name = name;
				this.Price = price;
                this.Tax = tax;
        }

            static void getTax(Product obj)
            {            
                    obj.Tax = obj.Qty * 10;
                    Console.WriteLine("{0} {1} at {2} Tax {3}", obj.Qty, obj.Name, obj.Price, obj.Tax);
            }

            static void Main(string[] args)
            {
                Console.WriteLine("Scenario 1:");
                List<Product> ProductList = new List<Product>();
                ProductList.Add(new Product(1, "book", 10, 5));
                ProductList.Add(new Product(1, "music CD", 20, 0));

                ProductList.ForEach(getTax);
                
				double res = ProductList.Sum(x => x.Tax);
				Console.WriteLine("Sales: " + res);

            }
        }
     }
}


;