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

后端 未结 14 2420
谎友^
谎友^ 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:47

    Sometimes explanations won't help especially for the beginners. You can imagine value type as data file and reference type as a shortcut to a file.

    So if you copy a reference variable you only copy the link/pointer to a real data somewhere in memory. If you copy a value type, you really clone the data in memory.

提交回复
热议问题