VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • C# |检查列表字典是否为只读

C# |检查列表字典是否为只读

原文:https://www . geesforgeks . org/c-sharp-check-if-list dictionary-只读/

列表词典。IsReadOnly 属性用于获取一个值,该值指示列表字典是否是只读的。

语法:

public bool IsReadOnly { get; }

返回值:该属性始终返回 false 。

例:

// C# code to check if ListDictionary is read-only
using System;
using System.Collections;
using System.Collections.Specialized;

class GFG {

    // Driver code
    public static void Main()
    {

        // Creating a ListDictionary named myDict
        ListDictionary myDict = new ListDictionary();

        myDict.Add("Australia", "Canberra");
        myDict.Add("Belgium", "Brussels");
        myDict.Add("Netherlands", "Amsterdam");
        myDict.Add("China", "Beijing");
        myDict.Add("Russia", "Moscow");
        myDict.Add("India", "New Delhi");

        // Checking if ListDictionary is read-only
        Console.WriteLine(myDict.IsReadOnly);
    }
}

输出:

False

注意:

  • The read-only collection is not allowed to add, remove or modify elements after it is created.
  • A read-only collection is just a collection with a wrapper that prevents the collection from being modified. Therefore, if changes are made to the underlying collection, the read-only collection will reflect these changes.
  • Retrieving the value of this attribute is an O(1) operation.

参考:

  • https://docs。微软。com/en-us/dotnet/API/system。收藏品。专业的。列表词典。是只读的。视图=netframework-4.7.2


相关教程