Dilemma with using value types with `new` operator in C#

后端 未结 5 1308
后悔当初
后悔当初 2020-12-29 10:42

When operator new() is used with reference type, space for the instance is allocated on the heap and reference variable itself is placed on the stack. Besides t

5条回答
  •  醉酒成梦
    2020-12-29 11:18

    About zeroing of structs.

    Parameterless constructor zeroes members.

    If you don't use new(), you can't access struct members unless you initialize them on your own first. Otherwise you'll get "Use of possibly unassigned field".

提交回复
热议问题