简体   繁体   中英

How do i fix this code? C# Ptr to a struct

As you may know, the wall rect will not update since its a copy and not a reference. Is there a way for me to make a reference or pointer to r and not change this code? I suppose i could do a find/replace in the function but that something i try not to do.

//code to get wall
var r = wall.r;
//more code
r.Height += yDif;

It isn't going to work, you already know why. Avoid the copy or simply store the copy back:

//more code
r.Height += yDif;
wall.r = r;

This of course requires a setter.

//code to get wall
var r = wall.r;
//more code
r.Height += yDif;
wall.r = r;

Why don't you update directly the wall rect ?

//code to get wall
var r = wall.r;
//more code
wall.r.Height += yDif;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM