如何在 C# 中使用 NameValueCollection 類?


NameValueCollection 為一個鍵設定多個值。我們來看看如何在 C# 程式中使用它們。

設定集合 −

static NameValueCollection GetCollection() {
   NameValueCollection myCollection = new NameValueCollection();
   myCollection.Add("Tim", "One");
   myCollection.Add("John", "Two");
   myCollection.Add("Jamie", "Three");
   return myCollection;
}

現在使用 GetCollection() 方法使用“AllKeys”方法屬性來顯示所有鍵 −

NameValueCollection myCollection = GetCollection();
foreach (string key in myCollection.AllKeys) {
   Console.WriteLine(key);
}

更新於: 20-6 月-2020

532 瀏覽量

啟動你的事業

透過完成課程獲得認證

入門
廣告