How does one access a control from a static method?

前端 未结 10 1931
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 12:50

I have an application in C# .NET which has a MainForm and a few classes.

One of these classes receives incoming data messages from a network. I need to

10条回答
  •  旧巷少年郎
    2020-11-30 13:34

    You can solve this problem by removing the static keyword.

    When you see "static", think: without an instance of this type.

    When you call a non-static method, you must explicitly use some instance. The method can access that instance using the "this" keyword.

    When you call a static method, there is no instance - you have abandoned the boundaries of OO and are now in a structural or functional programming context. If you want an instance of something, you need to bring it in as a parameter.

提交回复
热议问题