A static class can be accessed from anywhere in the application and maintains the values you have given it.
This is bad in the sense that you now have no idea what values the class contains because any part of that running application can change it at any moment.
So say you have a class which decodes a binary file into ASCII characters and stores it in a string so you can access it later.
public static class MyDecoder
{
public static String DecodedString;
public static Boolean DecodeFile(String myFile)
{
/* Do stuff to get bytes from file */
DecodedString = Encoding.ASCII.GetString(fileBytes);
return !String.IsNullOrWhiteSpace(DecodedString);
}
}
So what happens if you do this in your main application...
class Program
{
static void Main(string[] args)
{
Thread parseBinaryDataThread = new Thread(new ThreadStart(ParseBinaryDataA));
Thread parseBinaryDataThreadTwo = new Thread(new ThreadStart(ParseBinaryDataB));
parseBinaryDataThread.Start();
parseBinaryDataThreadTwo.Start();
// Never ever use Thread.Sleep(), but here I need to to simulate work
Thread.Sleep(2000);
Console.WriteLine(MyDecoder.DecodedString);
}
static void ParseBinaryDataA()
{
MyDecoder.DecodeFile("dataFileA.dat");
}
static void ParseBinaryDataB()
{
MyDecoder.DecodeFile("dataFileB.dat");
}
}
dataFileA.dat contains the string "Hello" in binary.
dataFileB.dat contains the String "World" in binary.
From the above, can you tell me what Console.WriteLine would print out?
There is a place for static variables and static classes. But they should only be used rarely and with great care. Instantiated classes should be the mainstay of any application with static classes converted into " Singletons " only where it is necessary.
Hope this managed to answer your question.
EDIT: Also, please don't confuse static classes and delegates. They are not the same thing ^^