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

 Posted on 11/01/2019

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.

Share On: facebook gplus twitter
Asked by Navin Gondoliya on 11/01/2019 Score: 24 points
Add Comment:


2 Answers

0 Corrected Answers
Aproved Answers
Answered by Shailesh Chaudhary on 11/6/2019 3:04:50 PM Score: 819 points

You can't call a non-static method without first creating an instance of its parent class.

So from the static method, you would have to instantiate a new object...

Vehicle myCar = new Vehicle();

... and then call the non-static method.



Add Comment:
Aproved Answers
Answered by Karishnamurthy Aiyar on 11/4/2019 7:24:16 AM Score: 45 points

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();
          public void NonStatic() { }


Add Comment:

Post Your Answers

Existing Members

Sign in to your account
Email Address
New Member?
Sign up and complete profile
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.