Published: Wednesday 27 September 2023
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?