2014年3月12日

【转载】#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 阅读(160) 评论(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 阅读(260) 评论(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) 编辑

2014年3月11日

【转载】#349 - The Difference Between Virtual and Non-Virtual Methods

摘要: In C#, virtual methods support polymorphism, by using a combination of the virtual and override keywords. With the virtual keyword on the base class method and the override keyword on the method in the derived class, both methods are said to be virtual.Methods that don't have either the virtual 阅读全文

posted @ 2014-03-11 20:59 yuthreestone 阅读(155) 评论(0) 推荐(0) 编辑

【转载】#346 - Polymorphism

摘要: Recall that polymorphism is one of the three core principles of object-oriented programming.Polymorphism is the idea that the same code can act differently, depending on the underlying type of the object being acted upon. The type of the object is determined at run-time, rather than at compile-time. 阅读全文

posted @ 2014-03-11 20:48 yuthreestone 阅读(171) 评论(0) 推荐(0) 编辑

【转载】#344 - Hidden Base Class Member Is Invoked Based on Declared Type of Object

摘要: When you use the new modifier to hide a base class method, it will still be called by objects whose type is the base class. Objects whose type is the derived class will call the new method in the derived class.1 Dog kirby = new Dog("kirby", 15);2 3 // Calls Dog.Bark4 kirby.Bark();5 6 Terri 阅读全文

posted @ 2014-03-11 20:30 yuthreestone 阅读(186) 评论(0) 推荐(0) 编辑

【转载】#336 - Declaring and Using a readonly Field

摘要: You can make a field in a class read-only by using the readonly modifier when the field is declared.In the example below, code that creates or uses instances of the Dog class will be able to read the SerialNumber field, but not write to it. 1 public class Dog 2 { 3 public string Name; 4 publ... 阅读全文

posted @ 2014-03-11 19:37 yuthreestone 阅读(171) 评论(0) 推荐(0) 编辑

【转载】#335 - Accessing a Derived Class Using a Base Class Variable

摘要: You can use a variable whose type is a base class to reference instances of a derived class.However, using the variable whose type is the base class, you can use it to access only members of the base class and not members of the derived class.In the example below, we have two instances of the Terrie 阅读全文

posted @ 2014-03-11 19:28 yuthreestone 阅读(228) 评论(0) 推荐(0) 编辑

【转载】#330 - Derived Classes Do Not Inherit Constructors

摘要: A derived class inherits all of the members of a base class except for its constructors.You must define a constructor in a derived classunlessthe base class has defined a default (parameterless) constructor. If you don’t define a constructor in the derived class, the default constructor in the base 阅读全文

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

【转载】#324 - A Generic Class Can Have More than One Type Parameter

摘要: A generic class includes one or more type parameters that will be substituted with actual types when the class is used. If the class has more than one type parameter, all parameters must be substituted when the class is used.Here's an example of a generic class that stores two objects, each havi 阅读全文

posted @ 2014-03-11 11:48 yuthreestone 阅读(221) 评论(0) 推荐(0) 编辑

导航