本文整理汇总了C#中ReadOnlyList.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyList.Contains方法的具体用法?C# ReadOnlyList.Contains怎么用?C# ReadOnlyList.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlyList
的用法示例。
在下文中一共展示了ReadOnlyList.Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public void Test()
{
List<string> strings = new List<string>(new string[] { "a", "b", "c" });
ReadOnlyList<String> read = new ReadOnlyList<string>(strings);
strings.Add("d");
Assert.AreEqual(3, read.Count);
Assert.IsTrue(read.Contains("a"));
Assert.AreEqual(0, read.IndexOf("a"));
Assert.IsTrue(read.Contains("b"));
Assert.AreEqual(1, read.IndexOf("b"));
Assert.IsTrue(read.Contains("c"));
Assert.AreEqual(2, read.IndexOf("c"));
Assert.IsFalse(read.Contains("d"));
Assert.AreEqual(-1, read.IndexOf("d"));
Assert.AreEqual("a,b,c", String.Join(",", read.ToArray()));
Assert.AreEqual("a,b,c", String.Join(",", new List<String>(read).ToArray()));
string[] arcopy = new string[3];
read.CopyTo(arcopy, 0);
Assert.AreEqual("a,b,c", String.Join(",", arcopy));
System.Collections.IEnumerator en = ((System.Collections.IEnumerable)read).GetEnumerator();
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("a", en.Current);
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("b", en.Current);
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("c", en.Current);
Assert.IsFalse(en.MoveNext());
}
示例2: TestContains
public void TestContains() {
int[] integers = new int[] { 1234, 6789 };
ReadOnlyList<int> testList = new ReadOnlyList<int>(integers);
Assert.IsTrue(testList.Contains(1234));
Assert.IsFalse(testList.Contains(4321));
}