- Home
- .NET coding challenges
- Using an interface in C#
Using an interface in C#
A C# interface defines a contract. Essentially, it contains the signatures for the properties and methods. It does not have any implementations associated with them.
A class that inherits an interface must include all properties and methods from it. In-addition, the class can state the implementation for them.
Take this code:
public interface ICurrency
{
string? Symbol { get; }
decimal USDConversationRate { get; }
}
public class USDollarsCurrency : ICurrency
{
}
Why wouldn't this complie and how do we go about fixing it?
Give us your anonymous feedback regarding this page, or any other areas of the website.
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