本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.AddFirst方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.AddFirst方法的具体用法?C# JArray.AddFirst怎么用?C# JArray.AddFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JArray
的用法示例。
在下文中一共展示了JArray.AddFirst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFirst
public void AddFirst()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
a.AddFirst("First");
Assert.AreEqual("First", (string)a[0]);
Assert.AreEqual(a, a[0].Parent);
Assert.AreEqual(a[1], a[0].Next);
Assert.AreEqual(5, a.Count());
a.AddFirst("NewFirst");
Assert.AreEqual("NewFirst", (string)a[0]);
Assert.AreEqual(a, a[0].Parent);
Assert.AreEqual(a[1], a[0].Next);
Assert.AreEqual(6, a.Count());
Assert.AreEqual(a[0], a[0].Next.Previous);
}
示例2: AddFirstAddedTokenShouldBeFirst
public void AddFirstAddedTokenShouldBeFirst()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(2);
JValue v3 = new JValue(3);
JArray j = new JArray();
Assert.AreEqual(null, j.First);
Assert.AreEqual(null, j.Last);
j.AddFirst(v1);
Assert.AreEqual(v1, j.First);
Assert.AreEqual(v1, j.Last);
j.AddFirst(v2);
Assert.AreEqual(v2, j.First);
Assert.AreEqual(v1, j.Last);
j.AddFirst(v3);
Assert.AreEqual(v3, j.First);
Assert.AreEqual(v1, j.Last);
}
示例3: IndexOf
public void IndexOf()
{
JValue v1 = new JValue(1);
JValue v2 = new JValue(1);
JValue v3 = new JValue(1);
JArray j = new JArray();
j.Add(v1);
Assert.AreEqual(0, j.IndexOf(v1));
j.Add(v2);
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v2));
j.AddFirst(v3);
Assert.AreEqual(1, j.IndexOf(v1));
Assert.AreEqual(2, j.IndexOf(v2));
Assert.AreEqual(0, j.IndexOf(v3));
v3.Remove();
Assert.AreEqual(0, j.IndexOf(v1));
Assert.AreEqual(1, j.IndexOf(v2));
Assert.AreEqual(-1, j.IndexOf(v3));
}