标签:ace make name 简单 color ret new factory ogr
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); Box box= wrapFation.WrapProduct(func); Box box1=wrapFation.WrapProduct(func1); Console.WriteLine(box.Pro.Name); Console.WriteLine(box1.Pro.Name); } class Product { public string Name { get; set; } } class Box { public Product Pro { get; set; } } class WrapFation { public Box WrapProduct(Func<Product> getProduct) { Box box = new Box(); Product product = getProduct.Invoke(); box.Pro = product; return box; } } class ProductFactory { public Product MakePizza() { Product product = new Product(); product.Name = "Pizza"; return product; } public Product MakeToyCar() { Product product = new Product(); product.Name = "Toy Car"; return product; } } } }
一个简单的委托
标签:ace make name 简单 color ret new factory ogr
原文地址:https://www.cnblogs.com/zxbls/p/13185005.html