在基类静态字段和派生类 [英] Static fields in a base class and derived classes

查看:136
本文介绍了在基类静态字段和派生类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要的基类,如果我们有一些静态字段,然后会发生什么呢?

In an abstract base class if we have some static fields then what happens to them ?

时,其范围从它继承(从这个基类或只是类型继承的类每个子类有它的自己的副本的静态摘要基类)的领域呢?

Is their scope the classes which inherit from this base class or just the type from which it is inheriting (each subclass has it's own copy of the static field from the abstract base class)?

推荐答案

<$ C C>静态成员是完全特定于 声明类;子类没有得到单独副本。这里唯一的例外是仿制药;如果一个开放式泛型类型声明静态字段,字段是特定于该确切 组合的类型参数构成的封闭泛型类型;即美孚< INT> 将有单独的静态字段美孚<串> ,假设字段上定义美孚< T>

static members are entirely specific to the declaring class; subclasses do not get separate copies. The only exception here is generics; if an open generic type declares static fields, the field is specific to that exact combination of type arguments that make up the closed generic type; i.e. Foo<int> would have separate static fields to Foo<string>, assuming the fields are defined on Foo<T>.

这篇关于在基类静态字段和派生类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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