.comment-link {margin-left:.6em;}

Sunday, March 27, 2005

 

Cutting the Chain Of overriding


let's see how to Override a method in VB.NET


Class Parent 
    Public Overridable Sub Test() 
    End
Sub
End
Class


ClassChild 
    Inherits Parent 
    Public Overrides Sub
Test() 
    End
Sub
End
Class


ClassMoreChild 
    Inherits
Child 
    Public Overrides Sub Test() 
    End
Sub
End
Class


so can we cut the chain of permission for overriding the Test() method in Child ( i no more need anyone to be able to Override this method, my behaviour is the ultimate so i need to stop permitting my childs to override me )
we can do this in VB.NET by using NotOverridable so class child can be written like this :
ClassChild 
    Inherits Parent 
    Public NotOverridable Overrides Sub
Test() 
    End
Sub
End
Class


so now we get a compilation error in MoreChild . but how can we do this in C# ?
unfortunately it cant be done ............. this is another VB vs C# competetion features ...


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?