You cannot do what you want, at least not directly.
The type Color is a struct
. This is a value type. Each instance of Color
is a separate copy of the value. It is not possible to get two instances of Color
to refer to the same object, no more so that two instances of int
can refer to the same object.
Now you can hack something by including Color
in your class. The following has not been tested:
public class ColorByReference { Color TheColor {get;set;} } static ColorByReference color = new ColorByReference {Color = new Color(0,0,0,0)}; static void Main(string[] args) { ColorByReference otherColor = color; color.TheColor.B = 100; Console.WriteLine(otherColor.TheColor.B); Console.WriteLine(color.TheColor.B); Console.ReadLine(); }
source share