静态方法和动态方法调用的区别

来源:岁月联盟 编辑:exp 时间:2012-06-01

动态方法,在使用时需要先创建实例,才能调用实例方法,而静态方法则不需要,直接使用即可。

 
//定义静态方法
class SQLHelper   
    {
        public static string aaa()
        {
            return “你好"       
        }
    } 

调用:
SQLHelper.aaa(); // 类名.方法名
 
//定义动态方法
class SQLHelper   
    {
        public string aaa()
        {
            return “你好"       
        }
    }
调用:
SQLHelper  s =new SQLHelper ();
s.aaa();

 


摘自 虫虫(⊙o⊙)