【计算机基础】静态方法和非静态方法

女爷i 2022-04-10 06:24 323阅读 0赞

目录

非静态方法:

静态方法:static


非静态方法:

  1. public class SQLHelper
  2. {
  3. public int test()//非静态方法
  4. {
  5. return res;
  6. }
  7. }

非静态方调用的时候:

实例化类.方法

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. Response.Write(new SQLHelper().test ());//对非静态方法的调用
  4. }

静态方法:static

  1. public class SQLHelper
  2. {
  3. public static int test()//静态方法
  4. {
  5. return res;
  6. }
  7. }

静态方法调用:

类名.方法

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. Response.Write( SQLHelper.test ());//对静态方法的调用
  4. }

小编先理解到这里,欢迎指正!

发表评论

表情:
评论列表 (有 0 条评论,323人围观)

还没有评论,来说两句吧...

相关阅读