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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:15:47+00:00 2026-05-29T08:15:47+00:00

I am working on something and I have to instantiate the class. My question

  • 0

I am working on something and I have to instantiate the class. My question is where would I do that at? Would I do it before this:

public partial class Form1 : Form
    {
       InputClass myclass = new InputClass();
        public Form1()
        {
            InitializeComponent();
        }


Or

public partial class Form1 : Form
    {

        public Form1()
        {

        InputClass myclass = new InputClass();

            InitializeComponent();
        }

Here is another code I am working on but it is not working out to well this is what my code looks like right now:

public partial class Form1 : Form
{


    InputClass myClass = new InputClass();
    myClass.yourname = "";
    myClass.Banner = "";

 public Form1()
    {
        InitializeComponent();
    }

I am new to C# and I am trying to figure this out. I need to instantiate the class. Then when the page load add to set the labels text from the _banner variable. Then add code to set the property yourname from the text in the textbox when the user presses the button. Then i need to clear the textbox. I also have to display the name in a messagebox from the class.

 class InputClass
{
    public string _banner;
    private string _yourName;

    public InputClass(String _banner)
    {
        this._banner = _banner;
    }

    public string yourName
    {
        get { return _yourName; }
        set { _yourName = value; }
    }

}

}

  • 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-29T08:15:47+00:00Added an answer on May 29, 2026 at 8:15 am

    If you want to access your object from other methods in your class then you need to use a member field rather than a local variable.

    private InputClass myClass = new InputClass { YourName = "", Banner = "" };
    
    public Form1()
    {
        InitializeComponent();
    }
    

    Another option is to declare a member field but initialize it inside the constructor:

    private InputClass myClass;
    
    public Form1()
    {
        InitializeComponent();
        this.myClass = new InputClass { YourName = "", Banner = "" };
    }
    

    This isn’t too useful in your specific case, but it can be useful if you need to pass parameters from your constructor to the InputClass constructor.

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

Sidebar

Related Questions

I have the a simple LinqToSQL statement that is not working. Something Like this:
I'm working on legacy code that looks very similar to this: public class BaseParser
I'm working on configuring a RollingFileAppender in log4net programmatically. I have something like this
I'm working on asp.net (vb, maybe that can change something) I have a project
I would appreciate some help with something I working on and have not done
Last night I tried to put together something that I have had working since
This was working last night, but I must have accidentally changed something, because it
I'm working on a project in which I have a class, DeviceCommunicator , that
I am willing to develop a mobile application. I wish to have something working
For a long time now I have noticed something annoying when working on Web

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.