Ref problem

  • Thread starter Thread starter ~toki
  • Start date Start date
T

~toki

I need to write a value over a field of a structure.
.....
public struct ARSubMesh {
private Matrix matrix;
public void setMatrix ( Matrix mat ) {
this.matrix = mat;
}
}
.....
ARSubMesh mesh = getMesh("torus");
mesh.setMatrix ( mat );
.....

public ARSubMesh getMesh(string name) {
// find the mesh *name*
return mesh_found;
}

This don't work because getMesh create a *new* object.

I need some like "return ref mesh_found", but the compiler say "Hey, learn a
bit of c# or ask to the experts..."
Well, here i am, askin to the experts.

How can i write directly over the struct field matrix from a returned value?
 
If you want "reference" semantics, use a class not a struct. Just replace
"struct" by "class" and your example will work.

Bruno.
 
:) It works. Thanks!!

Bruno Jouhier said:
If you want "reference" semantics, use a class not a struct. Just replace
"struct" by "class" and your example will work.

Bruno.

learn
 
Back
Top