【转载】#336 - Declaring and Using a readonly Field
You can make a field in a class read-only by using the readonly modifier when the field is declared.
In the example below, code that creates or uses instances of the Dog class will be able to read the SerialNumber field, but not write to it.
public class Dog
{
public string Name;
public int Age;
public readonly string SerialNumber; public Dog(string name, int age, string serNumber)
{
Name = name;
Age = age;
SerialNumber = serNumber;
}
}
You can assign a value to a readonly field in only two different places:
- In the class constructor
- As part of the field's declartion
public readonly string BestFriend = "Man";
原文地址:#336 - Declaring and Using a readonly Field
【转载】#336 - Declaring and Using a readonly Field的更多相关文章
- react.js Warning: Failed form propType: You provided a value prop to a form field without an onChange handler. This will render a read-only field.
错误信息: eact.js:20483 Warning: Failed form propType: You provided a value prop to a form field without ...
- ReadOnly field saved with NULL value
On CRM opportunity form view, i added readonly="1" for probability field. When i saved, wh ...
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- Just4Fun - Comparaison between const and readonly in C#
/* By Dylan SUN */ Today let us talk about const and readonly. const is considered as compile-time c ...
- readonly
readonly 关键字是可以在字段上使用的修饰符. 当字段声明包括 readonly 修饰符时,该声明引入的字段赋值只能作为声明的一部分出现,或者出现在同一类的构造函数中. 示例 在此示例 ...
- static, readonly, const
static Use the static modifier to declare a static member, which belongs to the type itself rather t ...
- const, static and readonly
const, static and readonly http://tutorials.csharp-online.net/const,_static_and_readonly Within a cl ...
- A const field of a reference type other than string can only be initialized with null Error [duplicate]
I'm trying to create a 2D array to store some values that don't change like this. const int[,] hiveI ...
- Usage of readonly and const
Many new learners can not make sure the usage scenarios of readonly and const keywords. In my opinio ...
随机推荐
- Experimental Educational Round: VolBIT Formulas Blitz C
Description The numbers of all offices in the new building of the Tax Office of IT City will have lu ...
- sysbench 安装、使用和测试
摘要: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL.Oracle和Post ...
- 1.5 GO json转Map
使用GO将show slave status查询返回的json串转为Map类型 package main import ( "encoding/json" "fmt&qu ...
- ubuntu 重新启动 导致 Namenode无法启动
hadoop 单节点安装成功了之后,心情那是叫一个激动.不过后来不知道为什么系统相当的慢.于是就把系统重启了.但是不妙的是namenode各种无法启动. 原来的配置: core-site.xml &l ...
- 转载 Some indexes or index [sub]partitions of table VAS.TAB_PUB_CALLLOG have been marked unusable
http://www.xifenfei.com/2011/12/some-indexes-or-index-subpartitions-of-table-vas-tab_pub_calllog-hav ...
- axios拦截器搭配token使用
在了解到cookie.session.token的作用后学习token的使用 cookie是随着url将参数发送到后台,安全性最低,并且大小受限,不超过4kb左右,它的数据保存在客户端 session ...
- shell中各种括号()、(())、[]、[[]]、{}的作用和区别
查看原文 - CSDN
- sql server 笔记(数据类型/新建、修改、删除数据表/)
1.数据类型: Character 字符串 / Unicode 字符串 / Binary 类型 / Number 类型 / Date 类型 / 其他数据类型 详解:http://www.w3sc ...
- numpy初用
import numpy as np for k,v in stat.iteritems(): print k v.sort() #v = v[len(v)*3/100:len ...
- keil版本控制
keil5.15才有对git svn的支持,之前的有其它的svcs; http://www.keil.com/appnotes/files/apnt_279.pdf http://stdbit.c ...