C#标记符

Fields allow the following modifiers:

  • Static modifier static
  • Access modifiers public internal private protected
  • Inheritance modifier new
  • Unsafe code modifier unsafe
  • Read-only modifier readonly
  • Threading modifier volatile

The readonly modifier
The readonly modifier prevents a field from being modified after construction. A read-only field can be assigned only in its declaration or within the enclosing type’s constructor.
Field initialization
Field initialization is optional. An uninitialized field has a default value (0, \0, null, false). Field initializers run before constructors:

  • public int Age = 10;

Declaring multiple fields together
For convenience, you may declare multiple fields of the same type in a commaseparated list. This is a convenient way for all the fields to share the same  attributes and field modifiers. For example:

  • static readonly int legs = 8,
  • eyes = 2;

Methods allow the following modifiers:

  • Static modifier static
  • Access modifiers public internal private protected
  • Inheritance modifiers new virtual abstract override sealed
  • Partial method modifier partial
  • Unmanaged code modifiers unsafe extern

Instance constructors allow the following modifiers:

  • Access modifiers public internal private protected
  • Unmanaged code modifiers unsafe extern

You can pass an expression into another constructor as follows:

  • public Wine (decimal price, DateTime year) : this (price, year.Year) { }

转载于:https://www.cnblogs.com/henyihanwobushi/archive/2012/07/14/2591180.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值