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 阅读(188) 评论(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 阅读(229) 评论(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) 编辑

【转载】#323 - A Generic Class is a Template for a Class

摘要: A generic classs is a class that takes one or more type parameters, which it then uses in the definition of the class. It can be thought of as a template for a class.1 public class ThingContainer2 {3 private TParam theThing;4 5 public void SetThing(TParam newValue)6 {7 theThing = newValue;... 阅读全文

posted @ 2014-03-11 10:53 yuthreestone 阅读(280) 评论(0) 推荐(0) 编辑

【转载】#303 - Accessibility of Class Members

摘要: Members of a class can have different kinds of accessibility.An accessibility keyword indicates what source code can access the member. The different types of accessibility are:public -All code can access the memberprivate -Only other code in the class can access the memberprotected -Code in this cl 阅读全文

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

导航