标签:product datetime return ctf lin delegate wrap new log
using System; namespace ConsoleTese { class Program { public delegate int dele(int a, int b); static void Main(string[] args) { ProductFactory productFactory = new ProductFactory(); WrapFation wrapFation = new WrapFation(); Func<Product> func = new Func<Product>(productFactory.MakePizza); Func<Product> func1 = new Func<Product>(productFactory.MakeToyCar); Logger logger = new Logger(); Action<Product> action = new Action<Product>(logger.Log); Box box= wrapFation.WrapProduct(func, action); Box box1=wrapFation.WrapProduct(func1, action); Console.WriteLine(box.Pro.Name); Console.WriteLine(box1.Pro.Name); } class Logger { public void Log(Product product) { Console.WriteLine("产品名称:{0},发生时间:{1},价格是:{2}",product.Name,DateTime.UtcNow,product.Proce); } } class Product { public string Name { get; set; } public double Proce { get; set; } } class Box { public Product Pro { get; set; } } class WrapFation { public Box WrapProduct(Func<Product> getProduct,Action<Product> action) { Box box = new Box(); Product product = getProduct.Invoke(); if (product.Proce>=50) { action(product); } box.Pro = product; return box; } } class ProductFactory { public Product MakePizza() { Product product = new Product(); product.Name = "Pizza"; product.Proce = 100.00; return product; } public Product MakeToyCar() { Product product = new Product(); product.Name = "Toy Car"; product.Proce = 12.00; return product; } } } }
标签:product datetime return ctf lin delegate wrap new log
原文地址:https://www.cnblogs.com/zxbls/p/13185324.html