.net中 如果要返回l ist里面的某一个元素用哪个方法

来源:百度知道 编辑:UC知道 时间:2024/05/30 23:53:51

1.直接使用索引: list[int idx];
2.Find: T List.Find(Predicate<T> match), T List.FindLast(Predicate<T> match)
FindAll: List<T> List.FindAll (Predicate<T> match)跟上面一样,只不过返回一组集合。
参数match Predicate 委托,用于定义要搜索的元素应满足的条件(MSDN)。
另外还有FindIndex, FindLast, FindLastIndex
int List.FindIndex(Predicate<T> match)
int List.FindLastIndex(Predicate<T> match)
这两个方法返回的时候元素所在的位置,他们还各有2个重载,详细的请查阅MSDN。
int List.IndexOf(T),
int List.LastIndexOf(T),有点类似上面的FindIndex,不过查找的参数不太一样。两个重载的参数的位置也不太一样。

对象[索引] 必要时使用强制转换

直接用对象+索引就好了