c# - How to clone a RectangleF -


how clone (copy) rectanglef in c#?

there inelegant ways it, such new rectanglef(r.location, r.size), surely there's .copy or .clone method hiding somewhere? neither of compiles me, nor there appear copy constructor. suspect there's simple, c#-standard way of copying struct, haven't found yet.

in case matters, real objective make method returns offset version of rectangle (because, amazingly, rectanglef doesn't have such built in - has mutator method). best stab @ is:

public static rectanglef offset(rectanglef r, pointf offset) {     pointf oldloc = r.location;     return new rectanglef(new pointf(oldloc.x+offset.x, oldloc.y+offset.y), r.size); } 

(made uglier should astounding lack of addition operator pointf, that's issue.) there simpler way this?

rectanglef struct i.e. value type. consider following:

public class program {     struct s     {         public int i;     }      static void main(string[] args)     {         s s1 = new s();         s s2 = s1;          s1.i = 5;          console.writeline(s1.i);         console.writeline(s2.i);     } } 

the output is:

5 0 

because s struct i.e. s2 copy of s1.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -