public ref int GetData()
{
var myDataStructure = new MyDataStructure();
return ref myDataStructure.Data;
}
public class MyDataStructure
{
private int _data;
public ref int Data => ref _data;
}
The new C # 7 ref return function is used here. After GetData () returns, what is stored in memory? Full copy of MyDataStructure? Or just an integer?
If the instance of MyDataStructure is stored in memory, because someone keeps a reference to the field of this instance, why in this example cannot be stored in memory:
public ref string GetString()
{
string s = "a";
return ref s;
}
source
share