本文整理汇总了C#中JsonValue.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# JsonValue.Remove方法的具体用法?C# JsonValue.Remove怎么用?C# JsonValue.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonValue
的用法示例。
在下文中一共展示了JsonValue.Remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrayOperations
public void ArrayOperations()
{
JsonValue test = new JsonValue() { 1, 2, 3 };
Assert.That(test.Count, Is.EqualTo(3));
Assert.That(test.Contains(1), Is.True);
Assert.That(test.Contains(4), Is.False);
JsonValue[] values = new JsonValue[3];
test.CopyTo(values, 0);
for (int i = 0; i < 3; i++) {
Assert.That((int)values[i], Is.EqualTo((int)test[i]));
}
test.Remove(2);
Assert.That(test.Contains(1), Is.True);
Assert.That(test.Contains(2), Is.False);
Assert.That(test.Contains(3), Is.True);
Assert.That(test.IsReadOnly, Is.False);
Assert.That(test.IndexOf(1), Is.EqualTo(0));
test.Insert(1, 2);
Assert.That((int)test[1], Is.EqualTo(2));
Assert.That(test.Count, Is.EqualTo(3));
test.RemoveAt(1);
Assert.That((int)test[1], Is.EqualTo(3));
Assert.That(test.Count, Is.EqualTo(2));
test.Clear();
Assert.That(test.Count, Is.EqualTo(0));
test.Add(5);
Assert.That(test.Count, Is.EqualTo(1));
Assert.That((int)test[0], Is.EqualTo(5));
}
示例2: KVPCollection
public void KVPCollection()
{
JsonValue test = new JsonValue() {
{"one", 1},
{"two", 2},
{"three", 3},
};
test.Remove(new KeyValuePair<string, JsonValue>("one", 1));
Assert.That(test.Count, Is.EqualTo(2));
Assert.Throws<KeyNotFoundException>(() => test["one"].ToString());
KeyValuePair<string, JsonValue>[] dest = new KeyValuePair<string, JsonValue>[2];
test.CopyTo(dest, 0);
for (int i = 0; i < 2; ++i) {
Assert.That(test[dest[i].Key].Equals(dest[i].Value));
}
Assert.That(test.Contains(new KeyValuePair<string, JsonValue>("two", 2)));
test.Add(new KeyValuePair<string, JsonValue>("four", 4));
Assert.That(test.ContainsKey("four"), Is.True);
Assert.That((int)test["four"], Is.EqualTo(4));
}
示例3: IDictionary
public void IDictionary()
{
JsonValue test = new JsonValue() {
{"one", 1},
{"two", 2},
{"three", 3}
};
Assert.That((int)test["one"], Is.EqualTo(1));
test["one"] = 5;
Assert.That((int)test["one"], Is.EqualTo(5));
test["one"] = 1;
var keys = test.Keys;
Assert.That(keys.Count, Is.EqualTo(3));
Assert.That(keys.Contains("one"), Is.True);
Assert.That(keys.Contains("two"), Is.True);
Assert.That(keys.Contains("three"), Is.True);
var values = test.Values;
Assert.That(values.Count, Is.EqualTo(3));
var intvalues = values.Select(x => (int)x).ToArray();
Array.Sort(intvalues);
for (int i = 0; i < 3; i++) {
Assert.That(intvalues[i], Is.EqualTo(i + 1));
}
test.Add("four", 4);
Assert.That(test.Count, Is.EqualTo(4));
Assert.That((int)test["four"], Is.EqualTo(4));
JsonValue val;
Assert.That(test.TryGetValue("one", out val), Is.True);
Assert.That((int)val, Is.EqualTo(1));
Assert.That(test.TryGetValue("seven", out val), Is.False);
Assert.That(val, Is.Null);
Assert.That(test.ContainsKey("four"), Is.True);
test.Remove("four");
Assert.That(test.Count, Is.EqualTo(3));
Assert.That(test.ContainsKey("four"), Is.False);
}