我可以使用受保护/私有静态变量来做什么? [英] What can I do with a protected/private static variable?

查看:84
本文介绍了我可以使用受保护/私有静态变量来做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到我可以写:

protected static

在我的C#类中(在我的情况下为aspx.cs)。以及:

in my C# class (in my case, an aspx.cs). As well as :

private static

是什么意思?静态无处不在。为什么要受保护/私有?

What does it means? Static is accessible everywhere. Why protected/private?

推荐答案

static的定义并非随处可见。它是在AppDomain范围内声明的类型之间共享的变量。

The definition of static isn't "available everywhere". It is a variable shared across the type it is declared within in the scope of an AppDomain.

访问修饰符不会更改此定义,但显然会影响访问范围。

Access Modifiers do not alter this definition, but obviously affect the scope of access.

您正在混淆 static 修饰符和访问修饰符。静态变量仍需要定义可访问性。在您的示例中,私有静态变量只能在定义它的类型内访问,protected可以在该类型和任何派生类型内访问。

You are confusing the static modifier with access modifiers. A static variable still needs accessibility defined. In your example, private static variables are only accessible within the type it is defined in, protected would be accessible within the type and any derived types.

请注意,注意IIS(承载ASP.NET应用程序)会回收工作进程,该工作进程将刷新当时仍存在的所有静态变量值。

Just a note, be aware that IIS (hosting ASP.NET applications) recycles worker processes, which will flush any static variable values that are alive at the time.

这篇关于我可以使用受保护/私有静态变量来做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆