1namespace InterfaceExample
2{
3 public class Computer
4 {
5 private IMobileStorage _usbDrive;
6
7 public IMobileStorage UsbDrive
8 {
9 get
10 {
11 return this._usbDrive;
12 }
13 set
14 {
15 this._usbDrive = value;
16 }
17 }
18
19 public Computer()
20 {
21 }
22
23 public Computer(IMobileStorage usbDrive)
24 {
25 this.UsbDrive = usbDrive;
26 }
27
28 public void ReadData()
29 {
30 this._usbDrive.Read();
31 }
32
33 public void WriteData()
34 {
35 this._usbDrive.Write();
36 }
37 }
38}
我想请教一下 第7行 重新定义个 UsbDrive 有什么好处?代码中,UsbDrive就是给_UsbDrive赋值,直接给_UsbDrive赋值不就可以了吗?而且用UsbDrive并没有杜绝_UsbDrive的使用额请教。。谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货