Since sel_activa is a value type, not a reference type, when you
"return" it in your "_sel_activa" property, you're returning a value
type, not a reference type, and therefore modifying it would be
worthless, since it wouldn't modify the original.

I'd recommend one of two things:
1) Make Selecction a class instead of a struct.
2) Have a method or property to change "x" instead of trying to access
the sel_activa object directly - for example:
public static void SetSelActivaX(bool newX) {
 sel_activa.x = newX;
}
or
public static bool SelActivaX
{ get { return sel_activa.x; } set { sel_activa.x = value; } }


On Feb 18, 9:06 am, Nacho108 <[email protected]> wrote:
> Hi everyone,
> I'm trying to create an structure so it can be seen from all forms. So
> doing a bit of research I decided to create an static property of the
> main class of the program.
>
> For this I've made this code:
>
> namespace WindowsApplication1
> {
>     static class Program
>     {
>         public struct Seleccion
>         {       public bool x;
>                 public bool y;         }
>
>         private static Seleccion sel_activa ;
>
>         public static Seleccion _sel_activa
>         {        get { return Program.sel_activa;}
>                  set { Program.sel_activa =value; }        }
>
>         static void Main()
>         {  Program.sel_activa = new Seleccion();
>             Application.EnableVisualStyles();
>             Application.SetCompatibleTextRenderingDefault(false);
>             Application.Run(new Form1());        }
>
> } }
>
> and after doing this I try to access the property from one form like
> this:
>
> Program._sel_activa.x = B02.Checked;    (B02 is a check box)
>
> and VS throw me an exception:
> "Cannot modify the return value of
> 'WindowsApplication1.Program._sel_activa' because it is not a
> variable"
>
> Can somebody help with this?
>
> By the way this is the link of the article I've taken from the
> information.http://bytes.com/groups/net-c/263680-accessing-same-data-multiple-for...
>
> Thanks in advance!

Reply via email to