SortedList 類中的 Capacity 屬性是什麼?


SortedList 類的 Capacity 屬性具有 SortedList 的最大大小。

SortedList 的預設容量為 16。

你可以嘗試執行以下程式碼以實現 C# 中 SortedList 類的 Capacity 屬性 −

示例

 即時演示

using System;
using System.Collections;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         SortedList s = new SortedList();

         s.Add("S1", "Maths");
         s.Add("S2", "Science");
         s.Add("S3", "English");
         s.Add("S4", "Economics");

         Console.WriteLine("Capacity = " + s.Capacity);
      }
   }
}

輸出

Capacity = 16

我們在前面首先向 SortedList 新增元素。

SortedList s = new SortedList();

s.Add("S1", "Maths");
s.Add("S2", "Science");
s.Add("S3", "English");
s.Add("S4", "Economics");

然後,我們找到了容量 −

s.Capacity

更新於: 2020-06-20

240 個瀏覽量

開啟您的 職業道路

完成課程以獲得認證

開始學習
廣告
© . All rights reserved.