I
I
Ilya2012-10-25 13:15:38
Programming
Ilya, 2012-10-25 13:15:38

How to reference an object in C#?

While learning C#, I ran into a problem unknown to me before, the question is probably funny and elementary, but it baffles me, on page 47 of Google I still gave up searching.
There is a class MainForm which has a public method public void goToDir(string path) {....};
There is another class in a separate Progress file, when I try to call the method by - MainForm.GoToDirectory(dest), I get that "For a non-static field, method or property "WApplication.MainForm.GoToDirectory(string)"
What should I do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2012-10-25
@Zerpico

Pass and store a reference to the MainForm object in the Progress class, or make the GoToDirectory method static.

S
Seter17, 2012-10-25
@Seter17

Apparently the GoToDirectory method should be made static. Either access the form instance MainForm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question