定义一基类:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.  
  6. namespace Demo  
  7. {  
  8.     public class Base  
  9.     {  
  10.         public virtual double Operation(double x, double y)   
  11.         {  
  12.             return x+y;  
  13.         }  
  14.     }     

第一层派生类Invoking中Override该Virtual方法并且声明该方法为sealed。则该方法不能被下一层中InvokingAgain类中所Override,但是,我们可以在一层中InvokingAgain类中隐藏Invoking中的sealed方法。贴上Demo更直观:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.  
  6. namespace Demo  
  7. {  
  8.     public class Invoking:Base  
  9.     {  
  10.         public sealed override double Operation(double x, double y)  
  11.         {  
  12.             return x*y;  
  13.         }  
  14.     }  
  15.  
  16.     public class InvokingAgain : Invoking   
  17.     {  
  18.         public double Operation(double x, double y)  
  19.         {  
  20.             return x / y;  
  21.         }  
  22.     }  

在Main中的调用及结果,有图有真相 (:D):

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.  
  6. namespace Demo  
  7. {  
  8.     class Program  
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.             Invoking invoking = new Invoking();  
  13.             Console.WriteLine(invoking.Operation(2,3));  
  14.  
  15.             InvokingAgain invokingAgain = new InvokingAgain();  
  16.             Console.WriteLine(invokingAgain.Operation(2, 3));  
  17.  
  18.             Console.ReadLine();  
  19.         }  
  20.     }  

理解sealed方法。_C#sealed方法