Published: Wednesday 13 September 2023
When using the abstract
modifier in C#, it indicates that the modifier has an incomplete implementation.
As well as a class, the abstract
modifier can be used in properties and methods.
A class with the abstract
modifier cannot be initalised directly. Instead, it needs to be inherited by a non-abstract class for it to be initalised.
Take this code:
public abstract class Currency
{
public abstract string Symbol { get; }
public abstract decimal USDConversationRate { get; }
}
public class USDollarsCurrency : Currency {
}
Why wouldn't this code snippet compile and what would we need to do to fix it?