meaning of static in c# code example
Example 1: c# static review
/*
- In general, static means “associated with the class, not an
instance”.
- A static member is always accessed by the class name, rather
than the instance name, like Forest.Area.
- A static method cannot access non-static members.
- A static constructor is run once per type, not per instance.
It is invoked before the type is instantiated or a static
member is accessed.
- Either of these would trigger the static constructor of Forest:
*/
public static void Main()
{
Forest f = new Forest();
}
// or
public static void Main()
{
Forest.Define();
}
/*
- A static class cannot be instantiated. Its members are accessed
by the class name, like Math.PI.
*/
Example 2: c# static meaning
In general, static means “associated with the class, not an instance”.
// Search c# static review for more detail
Example 3: static c#
(static) >> means that the method belongs to the Program class
and not an 'object' of the Program class.