Hello I have a WPF/C# application with 2 windows. I am trying to access a
public int myInt;
in my MainWindow from my OtherWindow:
MainWindow.myInt =3;
intellisense wont even allow me to access the variable.
Could someone please help?
Hello I have a WPF/C# application with 2 windows. I am trying to access a
public int myInt;
in my MainWindow from my OtherWindow:
MainWindow.myInt =3;
intellisense wont even allow me to access the variable.
Could someone please help?
You need to declare it as static
as you don't access it via an instance, but via class name. That said, it is usually not considered good design to expose fields publicly.
You either need to have an object:
MainWindow mw = new MainWindow();
mw.myInt = 3
Or you need to make rour field static
public static int myInt;
and call it like your are already doing:
MainWindow.myInt =3;