C# 调用类中的函数,一定要用该类的实例来引用吗,可以直接调用吗

解决方案 »

  1.   

    不一定,静态类(static class)中的函数就可以不实例化直接调用,调用方式如:类名.函数就可以了。
      

  2.   

    可以将该函数声明为Static函数..然后   类名.函数 就可以调用了
      

  3.   

    将方法定义为静态的就可以了
    ClassName.Method();
      

  4.   

    静态方法能够直接从类型名调用,不需要new对象
      

  5.   

    public static 加上这个关键字就行了
      

  6.   

    将方法定义为静态的就可以了 
    ClassName.Method();
      

  7.   

    public class mmm
    {
       public static int add(int a,int b)
       {
         return a+b;
       }
    }{ int h = mmm.add(1,5);  }
      

  8.   

    [code]public class mmm 

      state int c=0;
      public static int add(int a) 
      { 
        c+=a;
        return a+c; 
      } 
    } { int h = mmm.add(1);
      int k = mmm.add(3);
      }h=1;
    k=4;
    [/code]
      

  9.   

    public class mmm 

      state int c=0;
      public static int add(int a) 
      { 
        c+=a;
        return a+c; 
      } 
    } { int h = mmm.add(1);
      int k = mmm.add(3);
      }h=1;
    k=4;
      

  10.   

    你可以把你要访问的函数定义成静态函数,然后给这个静态函数用using起个别名。再以后用这个别名就应该可以了。
      

  11.   

    想到个方法
    做成DLL导出API,然后在项目中引用,这样貌似就可以不用输入类名了...示例就免了,网上还是比较多的...
      

  12.   

    不用静态函数,使用如下方式也可以:class A
    {
    private static A _a;
    public static A a
    {
    get {
    if (_a == null)
    {
    _a = new A();
    }
    return _a;
    }
    }
    public void ma()
    {
    }
    }A.ma();