Is there a way to call a non-static method from a static method?

Glimpse picture Glimpse · Apr 9, 2013 · Viewed 56.2k times · Source

Here's what I have.

public static void Person_home_phone_TextChanged(object sender, EventArgs e) { ... }

Is there any way to access non-static methods from the same or another class from inside this static method?

I need grab the text in the Person_home_phone text box and save it to a class data member.

Answer

Gabe picture Gabe · Apr 9, 2013

Example() -> Example

You would just need to create an instance of the type then call the non-static, from a static method.

public class Example(){

    public static void StaticExample()
    {

        Example example = new Example();
        example.NonStatic();
    }

    public void NonStatic()
    {

    }

}