KeyValuePair अपरिवर्तनीय है,
namespace System.Collections.Generic
{
[Serializable]
public struct KeyValuePair<TKey, TValue>
{
public KeyValuePair(TKey key, TValue value);
public TKey Key { get; }
public TValue Value { get; }
public override string ToString();
}
}
यदि आपके पास KeyValuePair में कोई मौजूदा मान है जिसे आप अपडेट करना चाहते हैं, तो आप मौजूदा मान को निकालने का प्रयास कर सकते हैं और फिर संशोधित मूल्य जोड़ सकते हैं
एक उदाहरण के लिए:
var list = new List<KeyValuePair<string, int>>();
list.Add(new KeyValuePair<string, int>("Cat", 1));
list.Add(new KeyValuePair<string, int>("Dog", 2));
list.Add(new KeyValuePair<string, int>("Rabbit", 4));
int removalStatus = list.RemoveAll(x => x.Key == "Rabbit");
if (removalStatus == 1)
{
list.Add(new KeyValuePair<string, int>("Rabbit", 5));
}