How to access fields from another class

后端 未结 2 1595
离开以前
离开以前 2021-01-17 07:13

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:



        
2条回答
  •  一个人的身影
    2021-01-17 07:32

    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.

提交回复
热议问题