2014年3月12日

【转载】#446 - Deciding Between an Abstract Class and an Interface

摘要: An abstract class is a base class that may have some members not implemented in the base class, but only in the derived classes. An interface is just a contract that a class can choose to fulfill - a list fo member that it must implement if it implements the interface.You'll often use an abstrac 阅读全文

posted @ 2014-03-12 17:20 yuthreestone 阅读(213) 评论(0) 推荐(0) 编辑

【转载】#445 - Differences Between an Interface and an Abstract Class

摘要: An interface provides a list of members, without an implementation, that a class can choose to implement. This is similar to an abstract class, which may include abstract methods that have no implementation in the abstract class, but might also include an implementation for some of its members.One d 阅读全文

posted @ 2014-03-12 17:10 yuthreestone 阅读(157) 评论(0) 推荐(0) 编辑

【转载】#443 - An Interface Cannot Contain Fields

摘要: An interface can contain methods, properties, events or indexers. It cannot contain fields.1 interface IMoo2 {3 // Methods4 void Moo();5 6 // Field not allow - compile-time error7 string Name;8 }Instead of a field, you can use a property.1 interface IMoo2 {3 // Methods4 voi... 阅读全文

posted @ 2014-03-12 16:59 yuthreestone 阅读(297) 评论(0) 推荐(0) 编辑

【转载】#440 - A Class Can Implement More than One Interface

摘要: It's possible for a class to implement more than one interface.For example, a Cow class might implement both the IMoo and the IMakeMilk interfaces. Multiple interfaces are listed after the class declaration, separated by commas. 1 public class Cow: IMoo, IMakeMilk 2 { 3 public void Moo() 4 {... 阅读全文

posted @ 2014-03-12 16:41 yuthreestone 阅读(271) 评论(0) 推荐(0) 编辑

【转载】#438 - Benefits of Using Interfaces

摘要: You might wonder why you'd define an interface, have a class implement that interface and then access the class through the interface instead of just using the class directly.One benefit of interface is that it allows you to treat different types of objects in the same way, provided that they im 阅读全文

posted @ 2014-03-12 16:25 yuthreestone 阅读(224) 评论(0) 推荐(0) 编辑

【转载】#437 - Access Interface Members through an Interface Variable

摘要: Onece a class implementation a particular interface, you can interact with the members of the interface through any instance of that class.1 Cow bossie = new Cow("Bossie", 5);2 3 // Cow implements IMoo, which includes Moo method4 bossie.Moo();You can also declare a variable whose type is a 阅读全文

posted @ 2014-03-12 14:45 yuthreestone 阅读(161) 评论(0) 推荐(0) 编辑

【转载】#402 - Value Equality vs. Reference Equality

摘要: When we normally think of "equality",we're thinking of value equality - the idea that the values stored in two different objects are the same. This is also known as equivalence. For example, if we have two different variables that both store an integer value of 12, we say that the vari 阅读全文

posted @ 2014-03-12 10:25 yuthreestone 阅读(261) 评论(0) 推荐(0) 编辑

【转载】#370 - Subscribe to an Event by Adding an Event Handle

摘要: You subscribe to a particular event in C# by defining an event handler-code that will be called whenever the event occurs (is raised). You then attach your event handler to an event on a specific object, using the += operator.Below is an example where we define an event handler for the Dog.Barked ev 阅读全文

posted @ 2014-03-12 09:20 yuthreestone 阅读(173) 评论(0) 推荐(0) 编辑

导航