- Home
- .NET coding challenges
- Initialising a C# static class won't compile
Initialising a C# static class won't compile
Static classes work in the same way as classes apart from one fundamental difference. They cannot be initalised.
Essentially, you are not able to use the new
operator on a static class.
Learn more about static classes and class members from the Microsoft website.
We have this static CategoryHelper
class.
public static class CategoryHelper
{
public static List<int> GetAllCategoryIds()
{
return new List<int>();
}
}
If we wanted to call the GetAllCategoryIds
method, how would we do it?
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