最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C# struct & class Differences
时间:2022-07-02 11:09:03 编辑:袖梨 来源:一聚教程网
C# struct/class Differences
struct Direct
{
//...
}
class InDirect
{
//...
}
Events are locked?
Exist on stack or heap?
Can cause garbage collection?
Meaning of this?
Always has a default constructor?
Default construction triggers static construction?
Can be null?
Use with the as operator?
Can be locked?
Can have a destructor?
Default field layout?
Can be a volatile field?
Can have synchronized methods?
Can be pointed to?
Can be stackalloc’d?
Can be sizeof’d?
How to initialize fields?
Inheritance differences?
Equals behavior
Events are locked?
Events declared in a class have their += and -= access automatically locked via a lock(this) to make them thread safe (static events are locked on the typeof the class). Events declared in a struct do not have their += and -= access automatically locked. A lock(this) for a struct would not work since you can only lock on a reference type expression.
struct Direct
{
//...
}
class InDirect
{
//...
}
Events are locked?
Exist on stack or heap?
Can cause garbage collection?
Meaning of this?
Always has a default constructor?
Default construction triggers static construction?
Can be null?
Use with the as operator?
Can be locked?
Can have a destructor?
Default field layout?
Can be a volatile field?
Can have synchronized methods?
Can be pointed to?
Can be stackalloc’d?
Can be sizeof’d?
How to initialize fields?
Inheritance differences?
Equals behavior
Events are locked?
Events declared in a class have their += and -= access automatically locked via a lock(this) to make them thread safe (static events are locked on the typeof the class). Events declared in a struct do not have their += and -= access automatically locked. A lock(this) for a struct would not work since you can only lock on a reference type expression.
相关文章
- 《原神》5.2卡池抽取建议 11-14
- 《原神》5.2版本新怪物介绍 11-14
- 《原神》希诺宁增伤触发方法 11-14
- 《原神》循音觅奇活动入口 11-14
- 《原神》循音觅奇兑换码获取方法 11-14
- 《原神》花羽会活动飞行技巧介绍 11-14