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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:23:00+00:00 2026-06-08T19:23:00+00:00

which code block to write and where to reach and assign? hi to all

  • 0

which code block to write and where to reach and assign?
hi to all sorry for the basic question but i will be happy if you can explain some Qs below. thanks.

 namespace forms
 {
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           // in thic code block what kind of things can i write or im allowed to write?   Q1
        }

        Form2 frm2 = new Form2();  // why should i write this line (since i already added form2 to my project as seen in the picture) ![enter image description here][1]to see frm2.Show(); in button1_Click part?   Q2
        //what happens in the background (from the compiler point of view) when i do Form2 frm2 = new Form2();?   Q3

        frm2.Show(); // why cant i reach frm2 in here? i just declared above.  Q4
        //just like that
        int number1; // i declare number variable in here
        number1= 5; // and why cant i assign number in here?

        // what kind of things can i write or allowed to write in this block ?   Q5
        // i sometimes confuse where i need to start writing the code or where i need to write or in which block ?

        public int number2;

        // ok now lets say i put a button on the form and when i double click it generated the code down below 
        //and now lets look in that code block

        private void button1_Click(object sender, EventArgs e)
        {    
           // ok now we are in this block and now it see when i write 
           frm2.Show();
            //or 
            //it see when i write 
           number1 = 5;   
           //ok now lets look at number1 and number2 what changes when i write public int and just int without public?  Q6
        } 
    }
}

enter image description here

  • 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-08T19:23:01+00:00Added an answer on June 8, 2026 at 7:23 pm

    First your code shouldn’t compile on line:

    frm2.Show();
    

    and

    number1= 5;
    

    These lines should be part of a method.

    Now to your questions.

    Q1. That’s the constructor block of Form1 class. You may do initialization and other stuff you want to be executed on first execution of the Form1.

    Q2. Your line

    Form2 frm2 = new Form2();
    

    is creating an instance for Form2, although you add the file to the project, to use Form2 you have to create an instance of it first.

    Q3. The above line is creating an instance of Form2, calling the constructor for Form2 and assigning the the instance of Form2 to its reference frm2

    Q4. You can’t do frm2.Show();, Only field definition and initialization can be done at class level. This line should be part of some method.

    Q5. Same answer as Q4

    Edit:
    Q6. If you specify public with int, that field will be accessible outside the class, and if you don’t specify anything then it is internal by default.

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

Sidebar

Related Questions

I have the following block of code which works fine; var boughtItemsToday = (from
I have a txt file which contains a google adsense code block and I'm
I am using the below code to block the taskbar which is working perfectly.
Which code snippet will give better performance? The below code segments were written in
I need to write a regular expression using php which parses the following code
Hello I have code which replaces document.write , makes a buffer and than pushes
whenever we need to exception handling, we will surround with try/catch block, but when
I'm trying to write code that can print only filled text boxes in the
I am currently trying to write some code which is going to send a
I have the following code block which connects out to a secure service (payment

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.