What is the difference between static methods in a Non static class and static methods in a static class?

前端 未结 4 1707
悲&欢浪女
悲&欢浪女 2020-12-02 20:28

I have two classes Class A and ClassB:

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

class Cla         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 20:37

    A static class can only contain static members.

    A static method ensures that, even if you were to create multiple classB objects, they would only utilize a single, shared SomeMethod function.

    Technically, there's no difference, except that ClassA's SomeMethod must be static.

提交回复
热议问题