首頁  >  文章  >  後端開發  >  如何在 C# 中使用 NameValueCollection 類別?

如何在 C# 中使用 NameValueCollection 類別?

WBOY
WBOY轉載
2023-09-18 08:33:071430瀏覽

如何在 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);
}

以上是如何在 C# 中使用 NameValueCollection 類別?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除