C# Readonly 关键字应用在 字典 或 集合
2012-02-19 23:35
471 查看
class Program
{
static void Main(string[] args)
{
tests ts = new tests();
ts.wrt();
Console.WriteLine(ts.lst.Count);
Console.Read();
}
}
class tests
{
public readonly int a = 5;
public readonly Dictionary<string, string> dic=new Dictionary<string,string>();
public readonly List<string> lst=new List<string>();
public void wrt()
{
a = 10;
dic["a"] = "";
lst.Add("a");
}
}
结果是 1 , 这就是说明 , 即使把 字典 或 集合对象 声明为 readonly , 也是可以对其插入数据的
{
static void Main(string[] args)
{
tests ts = new tests();
ts.wrt();
Console.WriteLine(ts.lst.Count);
Console.Read();
}
}
class tests
{
public readonly int a = 5;
public readonly Dictionary<string, string> dic=new Dictionary<string,string>();
public readonly List<string> lst=new List<string>();
public void wrt()
{
a = 10;
dic["a"] = "";
lst.Add("a");
}
}
结果是 1 , 这就是说明 , 即使把 字典 或 集合对象 声明为 readonly , 也是可以对其插入数据的
相关文章推荐
- 深入探讨C#中的const、readonly关键字
- C#中字典集合HashTable、Dictionary、ConcurrentDictionary三者区别
- C# Tips: 使用集合初始值设定项初始化字典
- C# 关键字const与readonly的区别
- 字典集合Dictionary<K,V>和构造的应用==>>体检套餐项目
- c#中的readonly和const关键字的认识
- c#中的params 关键字的应用(转)
- Unity3D中c#集合的应用
- C# 关键字集合,IDictionary
- c#集合在UNITY3D里的应用
- C#温故而知新学习系列之面向对象编程—readonly关键字(十七)
- C# 关键字const和readonly对比
- C#基础知识系列八(const和readonly关键字)
- C# 6 元组应用 Part 1:方便的字典工厂方法
- 关于 C# readonly 关键字的分析
- c#中的params 关键字的应用
- C# 5.0 两个新关键字 async await 在Silverlight中的应用
- c#中params关键字应用
- c# 关键字const(字段,局部变量),readonly(字段,数组)
- [转载]C#中字典集合的两种遍历