相关疑难解决方法(0)

非静态类中的静态方法与静态类中的静态方法有什么区别?

我有两个班级A和ClassB:

static class ClassA
{
    static string SomeMethod()
    {
        return "I am a Static Method";
    }
}

class ClassB
{
    static string SomeMethod()
    {
        return "I am a Static Method";
    }
}
Run Code Online (Sandbox Code Playgroud)

我想知道ClassA.SomeMethod();和之间有什么区别ClassB.SomeMethod();

如果可以在不创建类实例的情况下访问它们,为什么我们需要创建静态类而不是仅使用非静态类并将方法声明为静态?

c# oop static static-methods non-static

37
推荐指数
2
解决办法
4万
查看次数

标签 统计

c# ×1

non-static ×1

oop ×1

static ×1

static-methods ×1