C#中对虚拟属性和抽象属性的重写有什么异同

       public abstract class A

         {
             //抽象属性不能有实现代码
             public  abstract  string  AbstractProperty {  get set ; }
 
             string  s;
             //虚拟属性可以有实现代码
             public  virtual  string  VritualProperty
             {
                 get  return  this .s; }
                 set  this .s = value.ToUpper(); }
             }
         }
 
         public  class  B : A
         {
             string  message;
             //在继承类(子类)中必须提供抽象属性的实现
             public  override  string  AbstractProperty
             {
                 get  return  message; }
                 set  this .message = value; }
             }
 
             //重写属性可以调用基类中的实现
             public  override  string  VritualProperty
             {
                 get
                 {
                     return  base .VritualProperty;
                 }
                 set
                 {
                     base .VritualProperty = value;
                 }
             }
         }

猜你喜欢

转载自www.cnblogs.com/wfy680/p/12171348.html