0

How does CLR allocates memory in these 2 cases:
Are they both allocated in static memory area?

static class A 
{
    //Some methods
}

and

class A 
{
    //Some methods    
}
class B
{
    static A inst = new A();
    //Some methods
}

For the below statement, will the compiler

static A inst = new A();

allocate A in heap and assign it to static reference inst reference? Or it will create a static instance in High Frequency heap?

4

1 回答 1

0

静态字段与任何静态字段一样,无论类是静态的还是静态的。

静态类只是确保所有成员都是静态的语言技巧,仅此而已。在 .NET 中甚至不存在静态类:静态类将被转换为具有私有实例构造函数的“普通”类。这样就无法构造该类的实例。

于 2013-04-25T06:47:38.240 回答