- Home
- .NET coding challenges
- Using the abstract modifier in C#
How the abstract modifier works in a C# class
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?
Related challenges
Work out the number of days between two dates
Write a C# function to work out the difference between two dates and return the number of days in this coding challenge.
Contains online code editor