最新下载
热门教程
- 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.
相关文章
- 洛克王国缀星于夜活动怎么玩 05-04
- 崩坏星穹铁道杰哥存护流派强不强 05-04
- 今日小鸡庄园答案2024.5.4 05-04
- 蚂蚁庄园今日最新答案5.4 05-04
- 蚂蚁庄园今日答案最新2024.5.4 05-04
- 出行小贴士:没赶上火车,车票还能改签吗 蚂蚁庄园今日答案5月4日 05-04