zoukankan      html  css  js  c++  java
  • 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!

  • 相关阅读:
    canvas
    canvas -矩形
    canvas
    requestAnimationFrame
    flex in css
    让 .vue 支持 atom
    前端应该知道的基础知识汇总
    css伪类总结
    制作滑动门菜单
    页面布局中遇到菱形图片时的处理办法
  • 原文地址:https://www.cnblogs.com/juqiang/p/941324.html
Copyright © 2011-2022 走看看