c# when to use static code example

Example 1: static c#

(static) >> means that the method belongs to the Program class 
			and not an 'object' of the Program class.

Example 2: static class constructor c#

class SimpleClass
{
    // Static variable that must be initialized at run time.
    static readonly long baseline;

    // Static constructor is called at most one time, before any
    // instance constructor is invoked or member is accessed.
    static SimpleClass()
    {
        baseline = DateTime.Now.Ticks;
    }
}

Example 3: c# public static string

public static string saytest = "test";

private static void Main()
{
  Console.WriteLine(saytest);
}

Example 4: what is using static in c#

// The using static directive designates a type whose static 
// members and nested types you can access without specifying a type name.
using System;
using static System.Math;

public class Circle
{
   public Circle(double radius) 
   {
      Radius = radius;
   }
   public double Radius { get; set; }
   public double Diameter 
   {
      get { return 2 * Radius; }
   }
   public double Circumference 
   {
      get { return 2 * Radius * PI; }
      // otherwise if not using static "get { return 2 * Radius * Math.PI; }"
   }
   public double Area 
   {
      get { return PI * Pow(Radius, 2); }
     // otherwise if not using static "get { return Math.PI * Math.Pow(Radius, 2); }"
   }
}