日期:2014-05-18  浏览次数:20830 次

在 static 方法中,不能访问类的私有方法,那么该如何实现呢?
C# code

public static int GetNums()
{
    return ADD(3,2);
}

private int ADD(int a,int b)
{
    return a+b;
}



这样将会出错,因为在Static方法中不能访问私有成员,那么上面的这个需求应该怎么实现呢?(注:不能公开ADD方法)

------解决方案--------------------
C# code
public static int GetNums()
{
    return ADD(3,2);
}

private static int ADD(int a,int b)
{
    return a+b;
}