SortedList 类在 C# 中 IsReadOnly 属性是什么?


使用 IsReadOnly 属性来获取一个值,指示 SortedList 是否为只读。

可以尝试运行以下代码来在 C# 中实现 IsReadOnly 属性。

在此,我们首先设置 SortedList。

SortedList s = new SortedList();

添加元素。

s.Add("S001", "Jack");
s.Add("S002", "Henry");

现在检查 IsReadOnly。

Console.WriteLine("IsReadOnly = " + s.IsReadOnly);

以下是完整代码。

示例

 在线演示

using System;
using System.Collections;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         SortedList s = new SortedList();
         s.Add("S001", "Jack");
         s.Add("S002", "Henry");
         Console.WriteLine("IsReadOnly = " + s.IsReadOnly);
      }
   }
}

输出

IsReadOnly = False

更新于: 2020 年 6 月 23 日

78 次浏览

开启您的职业生涯

完成课程,获得认证

开始
广告
© . All rights reserved.