c#中的二级修饰符 - 常量,readonly

Const修饰,初始化一次,无法改变

 

public class constClass{

   public const string constVa= "this is a const";

   public constClass()

  { constVa = "this is not a const"  //编译错误}

}

 

也可以在函数中声明const

public void constMethod()

{

   const string constVa = "this is a fixed string";

   constVa = "this is a testing"  //编译错误

}

 

 

readonly 修饰符

 

同const,唯一区别在于可以在构造函数中初始化(别的不可以),另一个区别,const是默认static,访问使用constClass.constVa,但readonly不是的,需要另加static修饰,如public static readonly int readandstaticVa = 111;

 

 

partial修饰符 -  可以在多个cs文件中使用的变量,只能修饰在class或者struct上面,可以用来分下很大的类

employee.internal.cs

partial class employee{

...

}

 

employee.cs

public class employee{

 

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值