其实就一句话,为啥C#只能用class name来访问static method,而C++可以用instance和classname两种方式来做?为什么C#要这么设计?请大家帮助解答一下。 

I had a C++ static and C# static method design problem.

                In C++, we can call the static method through class name or the class instance. For example, the class defined here(In visual C++ 6.0)

                Class Test{

                                Public static void Hello(void){}

         }

We can call the static method by:

Test::Hello();

Or by :

Test t ;

t.Hello();

or by :

Test* t = new Test();

t->Hello();

but in C# , we can only access the method by the class name, can’t do it by using the instance call. I want to know, why we use this design in C# language?

Thanks!

相关文章:

  • 2021-09-10
  • 2022-02-10
  • 2021-09-14
  • 2021-10-24
  • 2021-11-02
  • 2022-01-31
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2021-11-07
  • 2022-12-23
  • 2021-09-16
  • 2021-05-22
  • 2022-01-19
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案