目录
非静态方法:
public class SQLHelper
{
public int test()//非静态方法
{
return res;
}
}
非静态方调用的时候:
实例化类.方法
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(new SQLHelper().test ());//对非静态方法的调用
}
静态方法:static
public class SQLHelper
{
public static int test()//静态方法
{
return res;
}
}
静态方法调用:
类名.方法
protected void Page_Load(object sender, EventArgs e)
{
Response.Write( SQLHelper.test ());//对静态方法的调用
}
小编先理解到这里,欢迎指正!
本文详细介绍了在编程中静态方法与非静态方法的区别及调用方式。非静态方法需要通过实例化类来调用,而静态方法则直接通过类名调用,无需实例化。文章通过具体代码示例,清晰地展示了两种方法的使用场景。
761

被折叠的 条评论
为什么被折叠?



