- 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?
Give us your anonymous feedback regarding this page, or any other areas of the website.
Related challenges
![Convert hours, minutes and seconds into a time formatted string](/media/btmhtazv/converttime.png?width=350&height=197&v=1dae8f912cb6030)
Convert hours, minutes and seconds into a time formatted string
Pass in the hours, minutes and seconds into a method and get it to return a time formatted string which should include leading zeros.
Contains online code editor
![Add an extension method to a C# class](/media/av3hn5uk/codingchallengeextensionmethods.png?width=350&height=197&v=1d9f38dc2398c70)