C# private, static, and readonly

前端 未结 9 751
忘掉有多难
忘掉有多难 2020-12-25 12:27

I was reviewing some code for log4net and I came across this.

private static readonly ILog logger = LogManager.GetLogger(typeof(AdminClient));
9条回答
  •  死守一世寂寞
    2020-12-25 13:21

    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?

提交回复
热议问题