C# return struct reference from method

后端 未结 2 575
独厮守ぢ
独厮守ぢ 2021-01-25 04:43

In C++, returning a reference of an object allocated on the stack in a method, yields garbage values due to the fact, that the stack object is destroyed as soon the method leave

2条回答
  •  青春惊慌失措
    2021-01-25 05:36

    keyword struct in C# is allow to describe value type. When you return value type from method, it creates new copy of it.

提交回复
热议问题