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 8501761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:17:53+00:00 2026-06-11T01:17:53+00:00

I apologize in advance with what will probably be a fairly easy/quick answer based

  • 0

I apologize in advance with what will probably be a fairly easy/quick answer based on scope, but I’ve looked everywhere and am surprised to not come up with an answer.

I have created a class called Soldier with roughly 100 class variables. I need a user to enter information and gradually build a Solider object over the course of several different class Forms (because there is too much data to collect on just one).

I create an (empty) instance of a Soldier (tempSoldier) in Form1.cs and start to set the object’s class variables that I collect from the user.

private void button1_Click(object sender, EventArgs e)
{
    Soldier tempSoldier = new Soldier();
    tempSoldier.surname = textbox1.text;
}

My question: how do I gain access to the object instance (tempSoldier) from Form1.cs in the other classes (Form2.cs, Form3.cs …)?

I should mention that all of the Forms (Form1.cs, Form2.cs …) share the same namespace.

Thanks in advance

Edit: All solutions below work so it just depends upon which one you like the best. Thank you for your feedback.
One little note, make sure you make ALL of the class modifiers Public including your custom class (in my case Soldier.cs).

  • 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-06-11T01:17:54+00:00Added an answer on June 11, 2026 at 1:17 am

    You’ll need to declare the Soldier instance in in a higher scope.

    One way of doing this would be to declare it inside Form1, then pass it to Form2, and so on.

    public class Form1
    {
        private Soldier tempSoldier = new Soldier();
    
        private void button1_Click(object sender, EventArgs e)
        {
            tempSoldier = new Soldier();
            tempSoldier.surname = textbox1.text;
        }
    
        private void GotoNextStep()
        {
            // pass the existing instance to the next form
            Form2 form2 = new Form2(tempSoldier);
    
            // display form 2 ...
        }
    }
    

    Another possibility is to use a singleton variable in a class that all the forms have access to.

    public class MyAppManager
    {
        private static readonly Soldier _soldier = new Solider();
    
        public static Soldier SoldierInstance
        {
            get { return _soldier; }
        }
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        MyAppManager.SoldierInstnace.surname = textbox1.text;
    }
    

    The former approach is ok if there’s a distinct sequence to the forms; the latter is better if difference forms could be used at different times or revisited.

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

Sidebar

Related Questions

I will apologize in advance as this post is born out of severe frustration.
Info: Apologies in advance as im not sure if my explanation will be sufficient.
I apologize in advance for not knowing how to better state this question. In
I apologize in advance if my question is not clear, because I don't know
I know what I want to do is probably easy and obvious but I
I apologize in advance about asking a so similar question, but i'm rather frustrated,
First off, I'd like to apologize in advance for not knowing this. I've been
I apologize in advance for the stupidity of this question, but I am confused
I apologize in advance for the long-winded question but I wanted to make sure
I apologize in advance if this is a duplicate, I'm not sure exactly what

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.