Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace skit_d_inaction
- {
- class Program
- {
- static void WriteCollection(Object[] collection)
- {
- foreach (var t in collection)
- {
- Console.WriteLine(t);
- }
- Console.WriteLine(Environment.NewLine);
- }
- static void Main(string[] args)
- {
- var products = Product.GetSamples();
- var suppliers = Supplier.GetSamples();
- var filtered0 = from p in products
- join s in suppliers
- on p.SupplierID equals s.ID
- select new { SupplierName = s.Name, ProductName = p.Name };
- var filtered1 = from p in products
- join s in suppliers
- on p.SupplierID equals s.ID
- where p.Price > 1000
- orderby p.Name, s.Name
- select new { SupplierName = s.Name, ProductName = p.Name };
- WriteCollection(filtered0.ToArray());
- WriteCollection(filtered1.ToArray());
- }
- }
- class Supplier
- {
- public string Name { get; set; }
- public uint ID { get; set; }
- public static Supplier[] GetSamples()
- {
- return new Supplier[]
- {
- new Supplier() { ID = 0, Name = "Apple" },
- new Supplier() { ID = 1, Name = "Samsung" },
- new Supplier() { ID = 2, Name = "Microsoft" },
- new Supplier() { ID = 3, Name = "Matarola inc" }
- };
- }
- }
- class Product
- {
- public string Name { get; set; }
- public decimal Price { get; set; }
- public uint SupplierID { get; set; }
- public Product(string name, string price, uint supplierID)
- {
- Name = name;
- Price = decimal.Parse(price);
- }
- public Product() { }
- public override string ToString()
- {
- return $"{Name}: {Price}";
- }
- public static Product[] GetSamples()
- {
- return new Product[]
- {
- new Product() { Name = "Product #1", Price = 1000, SupplierID = 0 },
- new Product() { Name = "Product #2", Price = 2000, SupplierID = 0 },
- new Product() { Name = "Product #3", Price = 3000, SupplierID = 1 },
- new Product() { Name = "Product #4", Price = 4000, SupplierID = 2 },
- new Product() { Name = "Product #5", Price = 5000, SupplierID = 3 }
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement