Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:25:38+00:00 2026-05-31T18:25:38+00:00

I am a newbie in windows forms and I need to store a string

  • 0

I am a newbie in windows forms and I need to store a string that i can check through out my program, I have created the DataAccessClass.cs, Controller.cs, Entity.cs, I have a Form1.cs and many user controls. So basically One of the User Controls gets a string in a textbox but other classes in my program or other controls may need to check on the value of that string capture before. I would need to do things like

if([theStringThatMustBeAccessibleThoriugOut].Equals("Something"))
 {
      //do something
 }

Again, i am a newbie and I would like an advise as to where to declare this variable, how to access it and how to store to it from any where and that it will be available anywhere. I know in asp.net i used to use Session["Blah"] and I would be able to get it at any point through out the life of the session. But in windows form i dont know how to do this..

Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:25:39+00:00Added an answer on May 31, 2026 at 6:25 pm

    You can always use a static variable of some class (which I’ll just call “Global”):

    public class Global {
      public static string TheString { get; set; }
    }
    

    Which can then be accessed from anywhere as Global.TheString.

    Be careful, though: static variables come with a cost. In particular, they can have negative effects on security and testability. For some reasons not to use static variables see the following:

    http://hardcoded-dev.blogspot.com/2009/05/bad-habits-static-variables.html

    http://gbracha.blogspot.com/2008/02/cutting-out-static.html

    If you want to avoid some (but not all) of the problems associated with statics:

    public class Global {
      private static Global _global = new Global();
      public static Global Instance { get { return _global; } set { _global = value; } }
      public TheString { get; set; }
    }
    

    Note now that TheString is no longer static, and Global.Instance can be changed at runtime. To access your special string, you can now use Global.Instance.TheString.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi friends, Am newbie for windows Development .i have created Grid With tabcontrol using
i need help with a little code that i have below. i'm a newbie
.NET newbie here... I'd like to make a button in a Windows form that
I am newbie to Windows Azure application. I have downloaded the Microsoft Visual Studio
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
I am a C# newbie and have a class that needs to pass row
I'm writing a .NET Windows Forms application that will post a message to a
Newbie to windows scripting. I need help running the .bat file on the command

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.