global class (simple question!)

Discussion in 'ASP .Net' started by ma, Aug 11, 2007.

  1. ma

    ma Guest

    Hello,
    I want to create a global class. To do this I did the followings:

    1- Create a class name test. It has a public variable named mystring.
    public class test

    {

    public string mystring = "hello world";

    }

    2- Create a global.asax and its coresponding global.asax.cs ( i did it using
    VC2005)
    3 - in global class generated by VC2005, I introduced test class as follow:

    public class Global : System.Web.HttpApplication

    {

    public test myclass;

    protected void Application_Start(object sender, EventArgs e)

    {

    }

    protected void Application_End(object sender, EventArgs e)

    {

    }

    }



    now I want to use it in an event in a mater page.



    I did this:

    public partial class Site1 : System.Web.UI.MasterPage

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    Response.Write(Application.myclass.mystring);

    }

    }

    but I am getting this error:

    Error 1 'System.Web.HttpApplicationState' does not contain a definition for
    'myclass'

    I do this:

    public partial class Site1 : System.Web.UI.MasterPage

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    Response.Write(Global.myclass.mystring);

    }

    }

    Error 1 An object reference is required for the nonstatic field, method, or
    property 'Global.myclass'



    What is wrong wioth my code?



    Regards
    ma, Aug 11, 2007
    #1
    1. Advertising

  2. ma

    John Mott Guest

    You need to declare the string as

    public static string mystring = "Hello World";

    I would recommend making it a property

    public static mystring {
    get { return "Hello World"; }
    }

    john
    nice clean examples at www.nicecleanexamples.com


    "ma" <> wrote in message
    news:...
    > Hello,
    > I want to create a global class. To do this I did the followings:
    >
    > 1- Create a class name test. It has a public variable named mystring.
    > public class test
    >
    > {
    >
    > public string mystring = "hello world";
    >
    > }
    >
    > 2- Create a global.asax and its coresponding global.asax.cs ( i did it
    > using VC2005)
    > 3 - in global class generated by VC2005, I introduced test class as
    > follow:
    >
    > public class Global : System.Web.HttpApplication
    >
    > {
    >
    > public test myclass;
    >
    > protected void Application_Start(object sender, EventArgs e)
    >
    > {
    >
    > }
    >
    > protected void Application_End(object sender, EventArgs e)
    >
    > {
    >
    > }
    >
    > }
    >
    >
    >
    > now I want to use it in an event in a mater page.
    >
    >
    >
    > I did this:
    >
    > public partial class Site1 : System.Web.UI.MasterPage
    >
    > {
    >
    > protected void Page_Load(object sender, EventArgs e)
    >
    > {
    >
    > Response.Write(Application.myclass.mystring);
    >
    > }
    >
    > }
    >
    > but I am getting this error:
    >
    > Error 1 'System.Web.HttpApplicationState' does not contain a definition
    > for 'myclass'
    >
    > I do this:
    >
    > public partial class Site1 : System.Web.UI.MasterPage
    >
    > {
    >
    > protected void Page_Load(object sender, EventArgs e)
    >
    > {
    >
    > Response.Write(Global.myclass.mystring);
    >
    > }
    >
    > }
    >
    > Error 1 An object reference is required for the nonstatic field, method,
    > or property 'Global.myclass'
    >
    >
    >
    > What is wrong wioth my code?
    >
    >
    >
    > Regards
    >
    >
    >
    >
    >
    >
    John Mott, Aug 11, 2007
    #2
    1. Advertising

  3. ma

    ma Guest

    Thanks, but I don 't want that my variable be static. It is an example but
    in realworld I want a variable which is not static. What should I do?

    Regards

    "John Mott" <> wrote in message
    news:...
    > You need to declare the string as
    >
    > public static string mystring = "Hello World";
    >
    > I would recommend making it a property
    >
    > public static mystring {
    > get { return "Hello World"; }
    > }
    >
    > john
    > nice clean examples at www.nicecleanexamples.com
    >
    >
    > "ma" <> wrote in message
    > news:...
    >> Hello,
    >> I want to create a global class. To do this I did the followings:
    >>
    >> 1- Create a class name test. It has a public variable named mystring.
    >> public class test
    >>
    >> {
    >>
    >> public string mystring = "hello world";
    >>
    >> }
    >>
    >> 2- Create a global.asax and its coresponding global.asax.cs ( i did it
    >> using VC2005)
    >> 3 - in global class generated by VC2005, I introduced test class as
    >> follow:
    >>
    >> public class Global : System.Web.HttpApplication
    >>
    >> {
    >>
    >> public test myclass;
    >>
    >> protected void Application_Start(object sender, EventArgs e)
    >>
    >> {
    >>
    >> }
    >>
    >> protected void Application_End(object sender, EventArgs e)
    >>
    >> {
    >>
    >> }
    >>
    >> }
    >>
    >>
    >>
    >> now I want to use it in an event in a mater page.
    >>
    >>
    >>
    >> I did this:
    >>
    >> public partial class Site1 : System.Web.UI.MasterPage
    >>
    >> {
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >>
    >> {
    >>
    >> Response.Write(Application.myclass.mystring);
    >>
    >> }
    >>
    >> }
    >>
    >> but I am getting this error:
    >>
    >> Error 1 'System.Web.HttpApplicationState' does not contain a definition
    >> for 'myclass'
    >>
    >> I do this:
    >>
    >> public partial class Site1 : System.Web.UI.MasterPage
    >>
    >> {
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >>
    >> {
    >>
    >> Response.Write(Global.myclass.mystring);
    >>
    >> }
    >>
    >> }
    >>
    >> Error 1 An object reference is required for the nonstatic field, method,
    >> or property 'Global.myclass'
    >>
    >>
    >>
    >> What is wrong wioth my code?
    >>
    >>
    >>
    >> Regards
    >>
    >>
    >>
    >>
    >>
    >>

    >
    >
    ma, Aug 11, 2007
    #3
  4. ma

    John Mott Guest

    If you're trying to create global variables you sorta do want them static.
    You can have something thats modifiable, not just a constant.

    static string _mystring = "";

    public static string mystring {
    get { return _mystring; }
    set { _mystring = value;}
    }

    The other option is to create an instance of the global class

    public class Global {
    public string mystring = "a default value";
    };

    public Global GlobalInstance = new Global();

    and then you can say

    GlobalInstance.mystring = "a new value";


    John
    nice clean examples at www.nicecleanexamples.com




    "ma" <> wrote in message
    news:...
    > Thanks, but I don 't want that my variable be static. It is an example but
    > in realworld I want a variable which is not static. What should I do?
    >
    > Regards
    >
    > "John Mott" <> wrote in message
    > news:...
    >> You need to declare the string as
    >>
    >> public static string mystring = "Hello World";
    >>
    >> I would recommend making it a property
    >>
    >> public static mystring {
    >> get { return "Hello World"; }
    >> }
    >>
    >> john
    >> nice clean examples at www.nicecleanexamples.com
    >>
    >>
    >> "ma" <> wrote in message
    >> news:...
    >>> Hello,
    >>> I want to create a global class. To do this I did the followings:
    >>>
    >>> 1- Create a class name test. It has a public variable named mystring.
    >>> public class test
    >>>
    >>> {
    >>>
    >>> public string mystring = "hello world";
    >>>
    >>> }
    >>>
    >>> 2- Create a global.asax and its coresponding global.asax.cs ( i did it
    >>> using VC2005)
    >>> 3 - in global class generated by VC2005, I introduced test class as
    >>> follow:
    >>>
    >>> public class Global : System.Web.HttpApplication
    >>>
    >>> {
    >>>
    >>> public test myclass;
    >>>
    >>> protected void Application_Start(object sender, EventArgs e)
    >>>
    >>> {
    >>>
    >>> }
    >>>
    >>> protected void Application_End(object sender, EventArgs e)
    >>>
    >>> {
    >>>
    >>> }
    >>>
    >>> }
    >>>
    >>>
    >>>
    >>> now I want to use it in an event in a mater page.
    >>>
    >>>
    >>>
    >>> I did this:
    >>>
    >>> public partial class Site1 : System.Web.UI.MasterPage
    >>>
    >>> {
    >>>
    >>> protected void Page_Load(object sender, EventArgs e)
    >>>
    >>> {
    >>>
    >>> Response.Write(Application.myclass.mystring);
    >>>
    >>> }
    >>>
    >>> }
    >>>
    >>> but I am getting this error:
    >>>
    >>> Error 1 'System.Web.HttpApplicationState' does not contain a definition
    >>> for 'myclass'
    >>>
    >>> I do this:
    >>>
    >>> public partial class Site1 : System.Web.UI.MasterPage
    >>>
    >>> {
    >>>
    >>> protected void Page_Load(object sender, EventArgs e)
    >>>
    >>> {
    >>>
    >>> Response.Write(Global.myclass.mystring);
    >>>
    >>> }
    >>>
    >>> }
    >>>
    >>> Error 1 An object reference is required for the nonstatic field, method,
    >>> or property 'Global.myclass'
    >>>
    >>>
    >>>
    >>> What is wrong wioth my code?
    >>>
    >>>
    >>>
    >>> Regards
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
    John Mott, Aug 11, 2007
    #4
  5. ma

    ma Guest

    Thanks John, But it doesn't work!

    I did this in the page load event:

    protected void Page_Load(object sender, EventArgs e)

    {

    Global GlobalInstance=new Global();

    Response.Write(GlobalInstance.myclass.mystring);

    GlobalInstance.myclass.mystring = "new string";

    }



    so the first time that I load this page, it should show "Hello World" and
    the next time that I download the page ( or refresh it) it should show "new
    string" but it always show "hello world"

    Any suggestion?

    Regards




    "John Mott" <> wrote in message
    news:%...
    > If you're trying to create global variables you sorta do want them static.
    > You can have something thats modifiable, not just a constant.
    >
    > static string _mystring = "";
    >
    > public static string mystring {
    > get { return _mystring; }
    > set { _mystring = value;}
    > }
    >
    > The other option is to create an instance of the global class
    >
    > public class Global {
    > public string mystring = "a default value";
    > };
    >
    > public Global GlobalInstance = new Global();
    >
    > and then you can say
    >
    > GlobalInstance.mystring = "a new value";
    >
    >
    > John
    > nice clean examples at www.nicecleanexamples.com
    >
    >
    >
    >
    > "ma" <> wrote in message
    > news:...
    >> Thanks, but I don 't want that my variable be static. It is an example
    >> but in realworld I want a variable which is not static. What should I do?
    >>
    >> Regards
    >>
    >> "John Mott" <> wrote in message
    >> news:...
    >>> You need to declare the string as
    >>>
    >>> public static string mystring = "Hello World";
    >>>
    >>> I would recommend making it a property
    >>>
    >>> public static mystring {
    >>> get { return "Hello World"; }
    >>> }
    >>>
    >>> john
    >>> nice clean examples at www.nicecleanexamples.com
    >>>
    >>>
    >>> "ma" <> wrote in message
    >>> news:...
    >>>> Hello,
    >>>> I want to create a global class. To do this I did the followings:
    >>>>
    >>>> 1- Create a class name test. It has a public variable named mystring.
    >>>> public class test
    >>>>
    >>>> {
    >>>>
    >>>> public string mystring = "hello world";
    >>>>
    >>>> }
    >>>>
    >>>> 2- Create a global.asax and its coresponding global.asax.cs ( i did it
    >>>> using VC2005)
    >>>> 3 - in global class generated by VC2005, I introduced test class as
    >>>> follow:
    >>>>
    >>>> public class Global : System.Web.HttpApplication
    >>>>
    >>>> {
    >>>>
    >>>> public test myclass;
    >>>>
    >>>> protected void Application_Start(object sender, EventArgs e)
    >>>>
    >>>> {
    >>>>
    >>>> }
    >>>>
    >>>> protected void Application_End(object sender, EventArgs e)
    >>>>
    >>>> {
    >>>>
    >>>> }
    >>>>
    >>>> }
    >>>>
    >>>>
    >>>>
    >>>> now I want to use it in an event in a mater page.
    >>>>
    >>>>
    >>>>
    >>>> I did this:
    >>>>
    >>>> public partial class Site1 : System.Web.UI.MasterPage
    >>>>
    >>>> {
    >>>>
    >>>> protected void Page_Load(object sender, EventArgs e)
    >>>>
    >>>> {
    >>>>
    >>>> Response.Write(Application.myclass.mystring);
    >>>>
    >>>> }
    >>>>
    >>>> }
    >>>>
    >>>> but I am getting this error:
    >>>>
    >>>> Error 1 'System.Web.HttpApplicationState' does not contain a definition
    >>>> for 'myclass'
    >>>>
    >>>> I do this:
    >>>>
    >>>> public partial class Site1 : System.Web.UI.MasterPage
    >>>>
    >>>> {
    >>>>
    >>>> protected void Page_Load(object sender, EventArgs e)
    >>>>
    >>>> {
    >>>>
    >>>> Response.Write(Global.myclass.mystring);
    >>>>
    >>>> }
    >>>>
    >>>> }
    >>>>
    >>>> Error 1 An object reference is required for the nonstatic field,
    >>>> method, or property 'Global.myclass'
    >>>>
    >>>>
    >>>>
    >>>> What is wrong wioth my code?
    >>>>
    >>>>
    >>>>
    >>>> Regards
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    ma, Aug 11, 2007
    #5
  6. ma

    John Mott Guest

    "ma" <> wrote in message
    news:...
    > Thanks John, But it doesn't work!
    >
    > I did this in the page load event:
    >
    > protected void Page_Load(object sender, EventArgs e)
    >
    > {
    >
    > Global GlobalInstance=new Global();
    >
    > Response.Write(GlobalInstance.myclass.mystring);
    >
    > GlobalInstance.myclass.mystring = "new string";
    >
    > }
    >
    >
    >
    > so the first time that I load this page, it should show "Hello World" and
    > the next time that I download the page ( or refresh it) it should show
    > "new string" but it always show "hello world"
    >
    > Any suggestion?
    >
    > Regards
    >


    Make the Global class itself static, like this

    public static class Global {
    public static string myString = "default";
    }

    Then you should be able to just refer to it without creating it with

    Global.myString = "set me";

    john

    nice clean examples at www.nicecleanexamples.com
    John Mott, Aug 11, 2007
    #6
  7. ma

    ma Guest

    Thanks.
    Is there any other way to instantiate an object with application scope?
    Regards



    "John Mott" <> wrote in message
    news:...
    >
    > "ma" <> wrote in message
    > news:...
    >> Thanks John, But it doesn't work!
    >>
    >> I did this in the page load event:
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >>
    >> {
    >>
    >> Global GlobalInstance=new Global();
    >>
    >> Response.Write(GlobalInstance.myclass.mystring);
    >>
    >> GlobalInstance.myclass.mystring = "new string";
    >>
    >> }
    >>
    >>
    >>
    >> so the first time that I load this page, it should show "Hello World" and
    >> the next time that I download the page ( or refresh it) it should show
    >> "new string" but it always show "hello world"
    >>
    >> Any suggestion?
    >>
    >> Regards
    >>

    >
    > Make the Global class itself static, like this
    >
    > public static class Global {
    > public static string myString = "default";
    > }
    >
    > Then you should be able to just refer to it without creating it with
    >
    > Global.myString = "set me";
    >
    > john
    >
    > nice clean examples at www.nicecleanexamples.com
    >
    ma, Aug 11, 2007
    #7
  8. ma

    John Mott Guest

    You can create a static member of the Application class (a static member can
    be an object that can be modified, it doesn't have to be read-only). That
    was my first idea but you didn't want a static variable. You may have
    thought from that context that static meant 'readonly', it doesn't.

    Does that help?

    here's a link as well:

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312607

    john


    "ma" <> wrote in message
    news:%...
    > Thanks.
    > Is there any other way to instantiate an object with application scope?
    > Regards
    >
    >
    >
    > "John Mott" <> wrote in message
    > news:...
    >>
    >> "ma" <> wrote in message
    >> news:...
    >>> Thanks John, But it doesn't work!
    >>>
    >>> I did this in the page load event:
    >>>
    >>> protected void Page_Load(object sender, EventArgs e)
    >>>
    >>> {
    >>>
    >>> Global GlobalInstance=new Global();
    >>>
    >>> Response.Write(GlobalInstance.myclass.mystring);
    >>>
    >>> GlobalInstance.myclass.mystring = "new string";
    >>>
    >>> }
    >>>
    >>>
    >>>
    >>> so the first time that I load this page, it should show "Hello World"
    >>> and the next time that I download the page ( or refresh it) it should
    >>> show "new string" but it always show "hello world"
    >>>
    >>> Any suggestion?
    >>>
    >>> Regards
    >>>

    >>
    >> Make the Global class itself static, like this
    >>
    >> public static class Global {
    >> public static string myString = "default";
    >> }
    >>
    >> Then you should be able to just refer to it without creating it with
    >>
    >> Global.myString = "set me";
    >>
    >> john
    >>
    >> nice clean examples at www.nicecleanexamples.com
    >>

    >
    >
    John Mott, Aug 11, 2007
    #8
  9. Hi there,

    Usually, when the class cannot be static and you require one global instance
    of a class, singleton pattern should be used (this is thread safe variant):


    public class Global
    {
    private Global()
    {
    }

    private static object sync = new object();
    private static Global instance = null;

    public Global Instance
    {
    get
    {
    lock(sync)
    {
    if (instance == null)
    {
    instance = new Global();
    }
    }
    return instance;
    }
    }
    }

    // usage
    Global global = Global.Instance;

    In addition, in ASP.NET there's build-in mechanism for such scenarios called
    Application state (instance can be initialized in the Global.asax
    Application_Start event) or Caching (you'd have to make sure race condition
    is eliminated).

    HTH
    --
    Milosz


    "ma" wrote:

    > Thanks.
    > Is there any other way to instantiate an object with application scope?
    > Regards
    >
    >
    >
    > "John Mott" <> wrote in message
    > news:...
    > >
    > > "ma" <> wrote in message
    > > news:...
    > >> Thanks John, But it doesn't work!
    > >>
    > >> I did this in the page load event:
    > >>
    > >> protected void Page_Load(object sender, EventArgs e)
    > >>
    > >> {
    > >>
    > >> Global GlobalInstance=new Global();
    > >>
    > >> Response.Write(GlobalInstance.myclass.mystring);
    > >>
    > >> GlobalInstance.myclass.mystring = "new string";
    > >>
    > >> }
    > >>
    > >>
    > >>
    > >> so the first time that I load this page, it should show "Hello World" and
    > >> the next time that I download the page ( or refresh it) it should show
    > >> "new string" but it always show "hello world"
    > >>
    > >> Any suggestion?
    > >>
    > >> Regards
    > >>

    > >
    > > Make the Global class itself static, like this
    > >
    > > public static class Global {
    > > public static string myString = "default";
    > > }
    > >
    > > Then you should be able to just refer to it without creating it with
    > >
    > > Global.myString = "set me";
    > >
    > > john
    > >
    > > nice clean examples at www.nicecleanexamples.com
    > >

    >
    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Aug 12, 2007
    #9
  10. ma

    ma Guest

    Thanks,
    Where can I read more about application instance or caching? Any good
    tutorial on the web?

    Regards

    "Milosz Skalecki [MCAD]" <> wrote in message
    news:...
    > Hi there,
    >
    > Usually, when the class cannot be static and you require one global
    > instance
    > of a class, singleton pattern should be used (this is thread safe
    > variant):
    >
    >
    > public class Global
    > {
    > private Global()
    > {
    > }
    >
    > private static object sync = new object();
    > private static Global instance = null;
    >
    > public Global Instance
    > {
    > get
    > {
    > lock(sync)
    > {
    > if (instance == null)
    > {
    > instance = new Global();
    > }
    > }
    > return instance;
    > }
    > }
    > }
    >
    > // usage
    > Global global = Global.Instance;
    >
    > In addition, in ASP.NET there's build-in mechanism for such scenarios
    > called
    > Application state (instance can be initialized in the Global.asax
    > Application_Start event) or Caching (you'd have to make sure race
    > condition
    > is eliminated).
    >
    > HTH
    > --
    > Milosz
    >
    >
    > "ma" wrote:
    >
    >> Thanks.
    >> Is there any other way to instantiate an object with application scope?
    >> Regards
    >>
    >>
    >>
    >> "John Mott" <> wrote in message
    >> news:...
    >> >
    >> > "ma" <> wrote in message
    >> > news:...
    >> >> Thanks John, But it doesn't work!
    >> >>
    >> >> I did this in the page load event:
    >> >>
    >> >> protected void Page_Load(object sender, EventArgs e)
    >> >>
    >> >> {
    >> >>
    >> >> Global GlobalInstance=new Global();
    >> >>
    >> >> Response.Write(GlobalInstance.myclass.mystring);
    >> >>
    >> >> GlobalInstance.myclass.mystring = "new string";
    >> >>
    >> >> }
    >> >>
    >> >>
    >> >>
    >> >> so the first time that I load this page, it should show "Hello World"
    >> >> and
    >> >> the next time that I download the page ( or refresh it) it should show
    >> >> "new string" but it always show "hello world"
    >> >>
    >> >> Any suggestion?
    >> >>
    >> >> Regards
    >> >>
    >> >
    >> > Make the Global class itself static, like this
    >> >
    >> > public static class Global {
    >> > public static string myString = "default";
    >> > }
    >> >
    >> > Then you should be able to just refer to it without creating it with
    >> >
    >> > Global.myString = "set me";
    >> >
    >> > john
    >> >
    >> > nice clean examples at www.nicecleanexamples.com
    >> >

    >>
    >>
    >>
    ma, Aug 12, 2007
    #10
  11. Hi,

    There are many tutorials out there, ie:
    http://samples.gotdotnet.com/quickstart/aspplus/doc/stateoverview.aspx
    Google is your friend

    Regards
    --
    Milosz


    "ma" wrote:

    > Thanks,
    > Where can I read more about application instance or caching? Any good
    > tutorial on the web?
    >
    > Regards
    >
    > "Milosz Skalecki [MCAD]" <> wrote in message
    > news:...
    > > Hi there,
    > >
    > > Usually, when the class cannot be static and you require one global
    > > instance
    > > of a class, singleton pattern should be used (this is thread safe
    > > variant):
    > >
    > >
    > > public class Global
    > > {
    > > private Global()
    > > {
    > > }
    > >
    > > private static object sync = new object();
    > > private static Global instance = null;
    > >
    > > public Global Instance
    > > {
    > > get
    > > {
    > > lock(sync)
    > > {
    > > if (instance == null)
    > > {
    > > instance = new Global();
    > > }
    > > }
    > > return instance;
    > > }
    > > }
    > > }
    > >
    > > // usage
    > > Global global = Global.Instance;
    > >
    > > In addition, in ASP.NET there's build-in mechanism for such scenarios
    > > called
    > > Application state (instance can be initialized in the Global.asax
    > > Application_Start event) or Caching (you'd have to make sure race
    > > condition
    > > is eliminated).
    > >
    > > HTH
    > > --
    > > Milosz
    > >
    > >
    > > "ma" wrote:
    > >
    > >> Thanks.
    > >> Is there any other way to instantiate an object with application scope?
    > >> Regards
    > >>
    > >>
    > >>
    > >> "John Mott" <> wrote in message
    > >> news:...
    > >> >
    > >> > "ma" <> wrote in message
    > >> > news:...
    > >> >> Thanks John, But it doesn't work!
    > >> >>
    > >> >> I did this in the page load event:
    > >> >>
    > >> >> protected void Page_Load(object sender, EventArgs e)
    > >> >>
    > >> >> {
    > >> >>
    > >> >> Global GlobalInstance=new Global();
    > >> >>
    > >> >> Response.Write(GlobalInstance.myclass.mystring);
    > >> >>
    > >> >> GlobalInstance.myclass.mystring = "new string";
    > >> >>
    > >> >> }
    > >> >>
    > >> >>
    > >> >>
    > >> >> so the first time that I load this page, it should show "Hello World"
    > >> >> and
    > >> >> the next time that I download the page ( or refresh it) it should show
    > >> >> "new string" but it always show "hello world"
    > >> >>
    > >> >> Any suggestion?
    > >> >>
    > >> >> Regards
    > >> >>
    > >> >
    > >> > Make the Global class itself static, like this
    > >> >
    > >> > public static class Global {
    > >> > public static string myString = "default";
    > >> > }
    > >> >
    > >> > Then you should be able to just refer to it without creating it with
    > >> >
    > >> > Global.myString = "set me";
    > >> >
    > >> > john
    > >> >
    > >> > nice clean examples at www.nicecleanexamples.com
    > >> >
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Aug 12, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,711
    Thomas Weidenfeller
    Oct 12, 2005
  2. christopher diggins
    Replies:
    16
    Views:
    733
    Pete Becker
    May 4, 2005
  3. Joseph Turian
    Replies:
    5
    Views:
    578
  4. Christian Maier
    Replies:
    3
    Views:
    490
    John Harrison
    Feb 15, 2007
  5. lost hope

    simple global variables question

    lost hope, Apr 28, 2005, in forum: Javascript
    Replies:
    10
    Views:
    195
    Dr John Stockton
    May 1, 2005
Loading...

Share This Page