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

  • SEARCH
  • Home
  • 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 6885755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:40:27+00:00 2026-05-27T05:40:27+00:00

I know the title might not be clear and I apologize about that. so

  • 0

I know the title might not be clear and I apologize about that.
so I have 2 forms in visual studio and in the first form user logs in to the system and the second form is where everything else happens.

I have called a class called info in the first form, and the class is responsible to gather user info and check for login etc. when a user logs into the system, the class takes the user ID and stores it into a private string. and from there the program goes into the second form.

now here is my question, how can I make this class global so I can access the stored userID from the second form? can I just create another instance of the class (info myinfo = new info()) ?

PS I am new to object oriented concept so Please user easy terms.

  • 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-27T05:40:27+00:00Added an answer on May 27, 2026 at 5:40 am

    Personally, I would vote against globals. Instead, I usually do it the following way:

    In the code that calls form 1, fetch the parameter from the form through a property. Pass it then to the second form through a parameter on the second form.

    E.g.:

    void Main()
    {
        var form1 = new Form1();
        form1.ShowDialog();
    
        var info = form1.GetInfo();
    
        var form2 = new Form2();
        form2.SetInfo( info );
        form2.ShowDialog();
    }
    

    If you really insist on having a global class, please look at the Singleton pattern, as wsanville pointed out. Basically it would roughly look like:

    public sealed class Info
    {
        private static Info _instance;
        private static readonly object _lock = new object();
    
        // Private to disallow instantiation.
        private Info()
        {
        }
    
        public static Info Instance
        {
            get
            {
                lock (_lock)
                {
                    if (_instance==null)
                    {
                        _instance = new Info();
                    }
                    return _instance;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title might not be clear enough because I don't know how to define
The title might not be clear, but I don't know how else to put
(using jQuery 1.4.4 edition) The title of the question might not be that clear,
I have a feeling that the title just might not be explanatory :) Setup
I know the title isn't very clear. I'm new to PHP, so there might
First off, I know the title is generic and not fitting. I just couldn't
I understand that the title might not be descriptive enough, but I'm making a
First of all, I just started PHP. I know my methods might not be
The title might not be clear, but I'll explain it here. I'm a total
Okay the question title may not have made sense... mostly because I don't know

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.