The static keyword is used to declare static members. This modifier can be used with classes, fields, methods, operators, etc. Without this operator we wouldn’t be able to do many things. But on the other hand I think it is sometimes overused. What’s more, sometimes people who use it do not realize the risk that is associated with it.

My friend, with whom I had pleasure to work, used to say each time that static is used it causes death of one software developer. In many situations he was totally right. Many times we have remove static elements during refactoring.

I think that the best way to demonstrate the issue is to present following example:

public static class A
{
  public static int a = B.b + 1;
}

public static class B
{
  public static int b = A.a + 1;
}

public class Program
{
    static void Main(string[] args)
    {
      Console.WriteLine("a: " + A.a);
      Console.WriteLine("b: " + B.b);
    }
}

And the question at the end. What will happen when I want to compile this code and then run it.