What is the difference between a reference type and value type in c#?

后端 未结 14 2458
谎友^
谎友^ 2020-11-21 05:13

Some guy asked me this question couple of months ago and I couldn\'t explain it in detail. What is the difference between a reference type and a value type in C#?

I

14条回答
  •  不思量自难忘°
    2020-11-21 05:54

    Value Type:

    • Fixed memory size.

    • Stored in Stack memory.

    • Holds actual value.

      Ex. int, char, bool, etc...

    Reference Type:

    • Not fixed memory.

    • Stored in Heap memory.

    • Holds memory address of actual value.

      Ex. string, array, class, etc...

提交回复
热议问题