有没有办法从静态方法调用非静态方法? [英] Is there a way to call a non-static method from a static method?
本文介绍了有没有办法从静态方法调用非静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我所拥有的.
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?
我需要抓取 Person_home_phone 文本框中的文本并将其保存到类数据成员中.
I need grab the text in the Person_home_phone text box and save it to a class data member.
推荐答案
Example() -> Example
Example() -> Example
您只需要创建 type
的实例,然后从 static
方法调用 non-static
.
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()
{
}
}
这篇关于有没有办法从静态方法调用非静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文