- 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
Removing the last character from a string
This coding challenge involves writing a C# method that will removing the last character from a string and returning the value.
Contains online code editor
Write a C# function to convert MPH to KPH
Take our coding challenge to write a C# function with the necessary parameters that converts miles-per-hour (MPH) to kilometres-per-hour (KPH) and vice-versa.
Contains online code editor