- Home /
Question by
cannatown · May 30, 2015 at 05:25 PM ·
c#javascriptstaticoop
Do you have to declare static properties and methods inside a static class?
Since declaring a class as static will automatically make all of its properties and methods static, do you still need to use the static keyword on properties and methods?
For example:
public static class MyClass : MonoBehaviour
{
public static int someProperty;
public static void MyFunction()
{
Debug.Log (someProperty);
}
}
Comment
But have you tried both ways before? Why not try it yourself ? Since the class cant be instantiated , the variables inside it are automatically static..
Best Answer
Answer by cjdev · May 30, 2015 at 08:01 PM
In C# a static class must have static properties and methods but it doesn't automatically make them that way, you have to specify it yourself. If you don't put the static keyword before the properties or methods you'll get a compiler error.
Your answer
