A question about C++ static method and C# static method

其实就一句话,为啥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!

posted @ 2007-10-29 13:10  鞠强  阅读(1110)  评论(8编辑  收藏  举报

hello

world