本文整理汇总了C#中System.Collections.ObservableCollection.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.IndexOf方法的具体用法?C# ObservableCollection.IndexOf怎么用?C# ObservableCollection.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.IndexOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexOf
/// <summary>
/// Find a tasklist by ID and then return its index
/// </summary>
/// <param name="observableCollection"></param>
/// <param name="taskList"></param>
/// <returns></returns>
private int IndexOf(ObservableCollection<TaskList> lists, TaskList taskList)
{
try
{
TaskList taskListRef = lists.Single(tl => tl.ID == taskList.ID);
return lists.IndexOf(taskListRef);
}
catch (Exception)
{
return -1;
}
}
示例2: IndexOfTest
public static void IndexOfTest()
{
string[] anArray = new string[] { "one", "two", "three", "four" };
ObservableCollection<string> collection = new ObservableCollection<string>((IEnumerable<string>)anArray);
for (int i = 0; i < anArray.Length; ++i)
Assert.Equal(i, collection.IndexOf(anArray[i]));
Assert.Equal(-1, collection.IndexOf("seven"));
Assert.Equal(-1, collection.IndexOf(null));
// testing that the first occurance is the index returned.
ObservableCollection<int> intCol = new ObservableCollection<int>();
for (int i = 0; i < 4; ++i)
intCol.Add(i % 2);
Assert.Equal(0, intCol.IndexOf(0));
Assert.Equal(1, intCol.IndexOf(1));
IList colAsIList = (IList)intCol;
var index = colAsIList.IndexOf("stringObj");
Assert.Equal(-1, index);
}
示例3: Test_ObservableCollection_IndexOf
public void Test_ObservableCollection_IndexOf()
{
var list = new ObservableCollection<int>() { 6, 5, 8 };
Assert.Equal(0, list.IndexOf(6));
Assert.Equal(1, list.IndexOf(5));
Assert.Equal(2, list.IndexOf(8));
}