第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

關(guān)于打印log的一些疑問

代碼:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace MorningExercise0920_Interface

{

? ? class Program

? ? {

? ? ? ? static void Main(string[] args)

? ? ? ? {

? ? ? ? ? ? WrapFactory wrapProduct = new WrapFactory();

? ? ? ? ? ? Logger logger = new Logger();

? ? ? ? ? ? IProductFactory pizze = new PizzeFactory();

? ? ? ? ? ? IProductFactory ToyCar = new ToyCarFactory();


? ? ? ? ? ? Action<Product> log = new Action<Product>(logger.Log);


? ? ? ? ? ? Box box1 = wrapProduct.WrapProduct(pizze, log);

? ? ? ? ? ? Box box2 = wrapProduct.WrapProduct(ToyCar, log);


? ? ? ? ? ? Console.WriteLine(box1.Product.Name);

? ? ? ? ? ? Console.WriteLine(box2.Product.Name);

? ? ? ? }

? ? }


? ? interface IProductFactory

? ? {

? ? ? ? Product Make();

? ? }

? ? class PizzeFactory : IProductFactory

? ? {

? ? ? ? public Product Make()

? ? ? ? {

? ? ? ? ? ? Product product = new Product();

? ? ? ? ? ? product.Name = "Pizze";

? ? ? ? ? ? product.Price = 78;

? ? ? ? ? ? return product;

? ? ? ? }

? ? }

? ? class ToyCarFactory : IProductFactory

? ? {

? ? ? ? public Product Make()

? ? ? ? {

? ? ? ? ? ? Product product = new Product();

? ? ? ? ? ? product.Name = "ToyCar";

? ? ? ? ? ? product.Price = 208;

? ? ? ? ? ? return product;

? ? ? ? }

? ? }


? ? class Logger

? ? {

? ? ? ? public void Log(Product product)

? ? ? ? {

? ? ? ? ? ? Console.WriteLine("TimeNow {0}\nProduct {1}\nPrice {2}", DateTime.Now, product.Name, product.Price);

? ? ? ? ? ? Console.WriteLine("**************************************************************");

? ? ? ? }

? ? }


? ? class Product

? ? {

? ? ? ? public string Name { get; set; }

? ? ? ? public double Price { get; set; }

? ? }

? ? class Box

? ? {

? ? ? ? public Product Product { get; set; }

? ? }

? ? class WrapFactory

? ? {

? ? ? ? public Box WrapProduct(IProductFactory ipProductor, Action<Product> logCallback)

? ? ? ? {

? ? ? ? ? ? Box box1 = new Box();

? ? ? ? ? ? box1.Product = ipProductor.Make();

? ? ? ? ? ? if (box1.Product.Price >= 1)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? logCallback(box1.Product);

? ? ? ? ? ? }

? ? ? ? ? ? return box1;

? ? ? ? }

? ? }

}

https://img1.sycdn.imooc.com//5ba304200001960807850310.jpg

我把2放在1前面debug就崩潰了,但是按照現(xiàn)在的1,2順序debug就能打印出log,請問下各位大神這是怎么回事呢?新手求解

正在回答

1 回答

2放在1前面獲取不到Price

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

星辰的淚 提問者

請問下為什么會獲取不到Price呢?
2018-10-18 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

關(guān)于打印log的一些疑問

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號