Question

This is a common question that i've been finding hard to understand

I have a form2 and a form1

on form2 i created a public variable this way, on class form2: form

 public partial class form2 : Form
 {
    public string xmlDialogconstante { get; private set; }
 }

It's supposed to be available on form2 and form1 i'm trying to call her on form1 using the following

form2.xmlDialogconstante

It gets me an error everytime, saying a reference is required, what does it means?

Was it helpful?

Solution

That is an instance property you need to create an instance of Form2 to access xmlDialogconstante or make it static.

You can create an instance and access your property like this, but if you don't initialize it before accessing you will get null.

form2 f = new form2();
string value = f.xmlDialogconstante;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top