static

Summary

The static modifier is used to declare a member as belonging to a class itself rather than its instances.

Syntax

static member

Parameters

member
The member to make 'static'.

Description

The static modifier is used to declare a member as belonging to a class itself rather than its instances. Thus, a static class member can be accessed without an instance of the class.

Module members are implicitly static so there is no need to declare them as such.

Examples

Static Field
1
2
3
4
class Foo
{
    static int bar = 1;
}
Static Method
1
2
3
4
5
6
7
class Foo
{
    static int bar()
    {
        return 1;
    }
}
Nested Class
1
2
3
4
5
6
class Foo
{
    static class Bar
    {
    }
}

See Also

Share

HTML | BBCode | Direct Link