- 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?
Give us your anonymous feedback regarding this page, or any other areas of the website.
Related challenges

Using a partial class in C#
Take our C# coding challenge where we add the partial keyword so we can add two identical class names without any compile errors.
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