C# private, static, and readonly

前端 未结 9 736
忘掉有多难
忘掉有多难 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:09

    static in c# means the member is associated with the class, and not with an instance of the class. Readonly is important because in c# most variables, and this one in particular, are reference variables. The readonly means that this variable will always reference the same logger.

提交回复
热议问题