I'm moving the object to another class, but there's a part I don't
know where to put ...
In the code I wrote I had :

        static void Main()
        {
            Program.sel_activa = new Seleccion();
            ... }

Main es the starting thread which is only in the program class. Where
should I put this line, or what should I do to define the sel_activa?





On Feb 19, 1:31 pm, nikhil gaitonde <[email protected]> wrote:
> you need not make any consideration for accessing it.
> Its always a good practice to have common variables that are needed across
> the applicationin a seperate file.
>
> Regards,
> Nikhil
>
> On Thu, Feb 19, 2009 at 4:29 PM, Nacho108 <[email protected]> wrote:
>
> > Thanks everybody for the answers.
>
> > Joe:
> > The code I post is a "simplification" of what I have really. Really I
> > have like more than 50 boolean variables that I would like to share
> > between forms. They are all states of checkboxes in a form.
> > So the real code would be:
>
> > public struct Seleccion { public bool x; public bool y;  public bool
> > z; etc } (like this 50 variables more)
>
> > So defining more than 50 class properties would be very long. That's
> > why I decided (maybe wrongly) to encapsulate all of them in an
> > structure.
> > Also defining a method for each variable would be very long.
>
> > Trying to find a solution, I tried to access the structure directly
> > from another forms, forgetting about the properties I defined and it
> > WORKED. I did it like this:
>
> > Program.sel_activa.x = B02.Checked;
>
> > So I could even define separate 50 boolean variables and access them
> > directly instead of an structure.
>
> > Is there something wrong with this approach?
> > I want to put clear that I'm just starting to learn object oriented
> > programming (I program in VB in a structured programming fashion only)
> > and that's why I'm asking this basic questions. Is there any advantage
> > in making them visible through properties?
> > I want to make this in the more suited "Object Oriented" way even if
> > it's long, but I just would like to know which advantages gives me all
> > the code I would have to type.
>
> > Nikhil:
>
> > What advantages would I have if I define it in a separate class? and
> > is there any consideration I have to take into account to make those
> > new class variables visible to all forms and classes?
>
> > Thanks in advance,
> > Regards!
> > Nacho
>
> > On Feb 18, 6:42 pm, nikhil gaitonde <[email protected]> wrote:
> > > Hi Nacho,
>
> > > Better don't use Program.cs to declare the property.
> > > Instead declare another static class just to declare variables across the
> > > application.
> > > Something like a Statemanager.cs
> > > Just let me know if this helps.
>
> > > Regards,
> > > Nikhil
>
> >  > On Wed, Feb 18, 2009 at 9:36 PM, 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