X++ 学习 (四)

方法和变量

1.方法的重载

跟Java一样的机制,默认情况下可以override,如果要把某个方法设为不可override,则要使用关键字final,要把某个类设为不可继承,也使用该关键字(C#里是sealed)

2.支持嵌入函数

void  MyMethod()
{
  
void  MyFunction()  // Embedded function only has scope within
  MyMethod
  {
    
// some statements
  }
  MyFunction();
}

这个在C++,Java,C#中都不支持.不过貌似意义不是太大。

3.静态成员

class  MyClass
{
  
// Variables could go here
   static   void  MyMethod()
  {
    
//  some statements
  }
  
void  MyMethod()
  {
    
//  some statements
  }
}

这个在C#里是不允许的,static不属于方法的签名,这两个方法属于同名方法。
调用

 

void  SomeMethod()
{
  MyClass mc 
=   new  MyClass();
  mc.MyMethod(); 
/*  The method in the current instance of the class (the object referred to as mc) is invoked. */
  mc::MyMethod(); 
//  The static method in the class is invoked
}

 

转载于:https://www.cnblogs.com/Kurodo/archive/2011/07/13/2105493.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值