I was reviewing some code for log4net and I came across this.
private static readonly ILog logger = LogManager.GetLogger(typeof(AdminClient));
Static variables falls in category of "class variables", a class variable is one that are associated with class instead of class object, on the other hand instance variables are variables that are associted with class object means each time a class object is intialized this object will have its own copy of that "Instance Variable" (non static) while static variable is shared among all objects of classes in running program like size of linked list etc. readonly is c# keyword that is used to make a variable readonly, java doesnt provide such facility you have to write a public method to access variables you dont wanna get tempered.
The reason to put a readonly flag on a private variable is to declare that the variable will always reference the same object. It's true that being private makes it invisible to anyone outside the class, but this way we can make sure we didn't accidentaly overwrite the variable with a new object, by writing something like
logger = LogManager.GetLogger(typeof(AdminClient));
somewhere else in our class. With readonly it just won't compile (Unless it was not initialized before, and we are in the (static) constructor)
Sorry, I know this has already been answered and it's really old, but I wanted to let anyone who comes across this article know that this is how you set up a "Singleton" pattern. Anyone who wants to know more about the code example in the question will likely benefit from learning more about Singletons and how they are used (mediators, loggers, async callbacks, etc.).
// mothership stuff about singletons
http://msdn.microsoft.com/en-us/library/ff650316.aspx
http://msdn.microsoft.com/en-us/library/ff650849.aspx
// a great SO discussion about them
What is so bad about singletons?