- Home
- .NET coding challenges
- Why does inheritance in a C# class not always compile?
Why does inheritance in a C# class not always compile?
Inheriting in C# is a great way to provide parent properties and methods to a number of different classes.
This means that common functionality can be shared across many different areas of an application reducing code bloat.
However, there are instances where inheriting can throw compile errors.
Take these classes:
public class Currency : CurrencyBase, CurrencyParent
{
}
public class CurrencyBase
{
}
public class CurrencyParent
{
}
The Currency
class is inheriting both the CurrencyBase
and CurrencyParent
class. Why will this code not compile?
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
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
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