79120639

Date: 2024-10-24 06:40:41
Score: 0.5
Natty:
Report link

It depends on how your code is structured. How are the struct members exposed? Are they public? You could encapsulate them by making the struct members private and the method public. Then, by returning ref from the method, you can ensure that no copies are made.

It could look something like this:

public class MyClass
{
  private MyStruct _myStruct;

  public ref MyStruct GetMyStruct()
  {
    return ref _myStruct;
  }
}

Again this is just how I understood your problem. Another solution might be better depending on your case since you have claimed it's not your personal project.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: user27314112