※ 引述《rz2x (弗朗西尔我婆)》之铭言:
建议笔记要调整一下顺序
# Value type
每次assignment都是pass by value.
int a = 1;
int b = a;
b = 3; // a == 1
# Reference type
每次assignment都是pass by reference. 所有reference指向同一物件
class foo{public int bar;};
foo f1 = new foo();
f1.bar = 0;
foo f2 = f1;
f2.bar = 2;
Console.WriteLine(f1.bar) // 2 因为f1 f2指向同一人, 容易出bug
Live demo: https://dotnetfiddle.net/z5NhhX
: 5.Class:类别,质型别,包含属性及方法,内存位在Heap上,可继承
: 6.Struct:结构,参考型别,包含属性及方法,内存位在Stack上,不可继承
C# class: reference type.
C# struct: value type.
为什么重要,主要是reference type, value type的特性差异
stack & heap在C#算是implementation detail 不用太在意
见"The Truth about Value Type"
https://ericlippert.com/2010/09/30/the-truth-about-value-types/
: 9.Field:字段,不具有get或set的变量
: 10.Property:属性,具有get或set的变量
getter setter可以做什么? 有什么好处? 才是他的意义
: 16.Stack:存放值的内存区块,系统自行配置。内存释放顺序为先进后出。
: 17.Heap:存放参考类型(物件)的内存区块,由使用者配置,若其中的指向为空,则记
: 忆体由GC自动释放。
同上 Eric Lippert那篇看完你可以跟面试官讨论:allocation的位置在C#重要嘛?
: 18.修饰子: public、private、protect、internal、sealed
应该说是access modifier
unsafe这种也算modifier
: 21.GC:Garbage Collection垃圾回收机制,系统自动搜寻内存中那些部分是曾用到但
: 现在不使用的,找到后会进行内存释放,其触发时间不固定
What are GC Generation 0/1/2?