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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:09:35+00:00 2026-06-18T04:09:35+00:00

I am trying to understand whats the difference between a static and public properties.

  • 0

I am trying to understand whats the difference between a static and public properties. But when I tried to access my public property ‘Test’ in other form it says ‘null’.

Heres Form1:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private string _test;

    public string Test
    {
        get { return _test; }
        set { _test = value; }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        _test = "This is a test";
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm2 = new Form2();
        frm2.Show();
    }
}

Here’s Form2:

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        Form1 frm1 = new Form1();
        label1.Text = frm1.Test;
    }
}

To check the value of ‘Test’ in Form1, I put a breakpoint to this line:

label1.Text = frm1.Test;

But the value is ‘null’.

Please help me how can I access public properties to other forms.

And BTW I tried to make this public property be a ‘public static’. I can access this using this:

Form1.Test

But I noticed that I can change ‘Test’ value from Form2 which I don’t want to happen. That’s why I am trying to use public property but with no luck. Can somebody clarify me these things. Thanks for all your help guys!

EDIT: (For follow up question) 

Sir John Koerner’s answer is the best answer for my question. But I have a follow up question, I tried to make these ‘test’ properties to be a ‘static’, and I noticed that even if I make this property a static or public property, it still can be edit in Form2. To make myself clear here’s a sample:

public partial class Form2 : Form
{
    private Form1 f1;
    public Form2(Form1 ParentForm)
    {
        InitializeComponent();
        f1 = ParentForm;
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        label1.Text = f1.Test;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        f1.Test = "This test has been changed!";

        this.Close();
    }
}

After Form2 closed, I tried to break again in Form1_Load to check value of ‘Test’, and it was changed! How can I make a public property in Form1 to readOnly in Form2 and cannot be editted? Please clarify to me. Thanks a lot guys!

  • 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-18T04:09:36+00:00Added an answer on June 18, 2026 at 4:09 am

    Your property is an instance variable, so the value can be different across different instances of Form1.

    If you are trying to access instance variables from a parent form, the easiest way to do that is to pass Form1 in to the constructor of Form2.

    public partial class Form2 : Form
    {
        private Form1 f1;
        public Form2(Form1 ParentForm)
        {
            InitializeComponent();
            f1 = ParentForm;
        }
    
        private void Form2_Load(object sender, EventArgs e)
        {
            label1.Text = f1.Test;
        }
    }
    

    Then when you create a new Form2 from Form1, you can do this:

    Form2 frm2 = new Form2(this);
    

    If you want your property to be read only, you can simply not specify a setter:

    public string Test
    {
        get { return _test; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand whats the difference between after update and for update triggers?
I am trying to understand whats the difference between Amazon S3 and Cloudfront ...
Been trying my best to understand this correctly. What is the difference between an
I am trying to understand what the difference is between string.find and string.match in
I am trying to understand the difference between $.when(...).then(...) $.when(...).done(...) in jQuery. As far
I'm trying to understand the difference between Django's ModelForm save method and saving the
I'm trying to understand what the difference is between two options rsync --size-only and
Possible Duplicate: Difference between Covariance & Contra-variance I'm trying to understand what covariance and
I am trying my best to understand what is the difference between ADO.NET -
I'm trying to understand the difference between working with just long, long2, long3, long4,

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.