访问静态字段与此类似。
类一旦被解析,就会以一种线程安全的方式修改原始代码位置以便直接访问静态字段的地址,因为此时已获知该地址。
Once the class has been resolved, the original code location is modified in a thread-safe way to access the static field's address directly because that address is then known.
这种做法并不常见,因为需要开发人员创建仅用于访问非实例(静态)方法和字段的对象的实例。
This is unusual because it requires a developer to create an instance of an object just to access non-instance (static) methods and fields!
此标志使得运行库能够在任何时候执行类型构造函数方法,只要该方法在第一次访问该类型的静态字段之前执行即可。
This flag allows the runtime to execute the type constructor method at any time it chooses, as long as the method executes before the first access to a static field for the type.
如果不需要访问某对象的字段,将方法设置为静态,调用会加速15%到20%。
If you don't need to access an object's fields, make your method static. Invocations will be about 15%-20% faster.
如果没有beforefieldinit,运行库就必须在某个精确时间运行类型构造函数,即,恰好在第一次访问该类型的静态或实例字段和方法之前。
Without beforefieldinit, the runtime must run the type constructor at a precise time-just before the first access to static or instance fields and methods of the type.
内部类会在外部类中任何需要访问mValue字段或调用doStuff方法的地方调用这些静态方法。
The inner class code calls these static methods whenever it needs to access the mValue field or invoke the doStuff method in the outer class.
如果你没必要访问对象的字段,那么使你的方法成为静态方法。
If you don't need to access an object's fields, make your method static.
支持导入常量:这个特性使静态方法和字段能够被导入,这样在访问静态成员时就不必使用完全限定的类名。
Support for importing constants: This facility allows static methods and fields to be imported, avoiding the need to use fully qualified class names when accessing static members.
如果您正在开发应用程序,并因此对包含静态字段的类型具有完全访问权限,则可以安全地禁止显示此规则发出的警告。
It is safe to suppress a warning from this rule if you are developing an application and therefore have full control over access to the type that contains the static field.
在域卸载过程中执行终止方法时,您可能需要访问另一个由静态字段引用并且有终止方法的对象。
While executing in your finalization method during domain unloading, you might want to access another object that is referenced by a static field and has a finalization method.
也可以调用类的静态方法或访问类的静态字段。
You can also call static methods on classes and access classes' static fields. Observe!
访问该程序集的每一应用程序域都必须具有静态数据的单独副本,以避免跨域边界引用静态字段中的对象。
Each application domain that accesses the assembly must have a separate copy of the static data, to prevent references to objects in static fields from crossing domain boundaries.
如果在不同的上下文中访问指示的静态字段,则该字段将包含不同的值。
If the indicated static field is accessed on a different context, it will contain a different value.
如果在不同的上下文中访问指示的静态字段,则该字段将包含不同的值。
If the indicated static field is accessed on a different context, it will contain a different value.
应用推荐