.NET: Why aren't Private Abstract methods allowed?
Sometimes when creating base objects you want to create methods that are overridden by object that inherit the base object, but keep the methods from being public. However, the compiler throws an exceptions when you try to define a method as Private Abstract.
Why doesn’t the compiler like “Private Abstract” methods?
The reason for this is Private methods can not be overridden. So, essentially the Abstract is useless if the method is Private.
How can I create a “Private” method that’s able to be overridden?
Simple, you just declare the method as Protected Abstract. Protected defines that the method is only accessible from within the class that declared it, and from within any derived class.
Related Posts
-
C#: How to Enumerate over Enum values and names
03 May 2024 -
C#: Console App that Accepts Command-Line Arguments
23 Apr 2024 -
C#: How to iterate over a dictionary?
20 Apr 2024 -
C#: What is the difference between 'string' and System.String?
16 Apr 2024