- Home
- .NET coding challenges
- Using a partial class in C#
Using a partial class in C#
By using partial classes in C#, we can split a class over two or more files.
This can be helpful to split out functionality across multiple files. In-addition, code can be added to an automatically generate class code without having to recreate it.
There is more information about partial classes on the Microsoft website.
Take this code:
public class Currency
{
public string? CurrencySymbol { get; }
}
public class Currency
{
public decimal? UsdCurrencyConversion { get; }
}
As there are two Currency
classes in the same namespace, this would not compile.
How would we make it compile without changing either of the class names?
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