当前位置:首页 > 开发 > C# > 正文内容

C# ArrayList

C#4年前 (2022-10-26)
添加的成员可以是任意类型    
ArrayList arrayList = new ArrayList();
string[] strs = new string[] { "a1", "b2", "c3" };
arrayList.Add(strs);        //此时arrayList拥有4个成员,成员类型为 String[]
arrayList.AddRange(strs);   //此时arrayList拥有4个成员,后续三个成员类型为String


搜索类型    
IndexOf    
IndexOf(Object)搜索指定的 Object,并返回整个 ArrayList 中第一个匹配项的从零开始索引。
IndexOf(Object, Int32)搜索指定的 Object,并返回 ArrayList 中从指定索引到最后一个元素这部分元素中第一个匹配项的从零开始索引。
IndexOf(Object, Int32, Int32)搜索指定的 Object,并返回 ArrayList 中从指定索引开始并包含指定元素数的这部分元素中第一个匹配项的从零开始索引。


BinarySearch    
BinarySearch(Object)使用默认的比较器在整个已排序的 ArrayList 中搜索元素,并返回该元素从零开始的索引。
BinarySearch(Object, IComparer)使用指定的比较器在整个已排序的 ArrayList 中搜索元素,并返回该元素从零开始的索引。
BinarySearch(Int32, Int32, Object, IComparer)使用指定的比较器在已排序 ArrayList 的某个元素范围中搜索元素,并返回该元素从零开始的索引。



lList转为ArrayList    
ArrayList.Adapter();

为一个特定 IList 创建一个 ArrayList 包装。

ArrayList转为任意类型    
NameAndPosition[] Files;
Files = (NameAndPosition[])files.ToArray(typeof(NameAndPosition));



转载请注明出处。

本文链接:http://pythonopen.com/?id=232

相关文章

C# Browsable(bool)

在编程中(比如常见的 C# 语言在开发 Windows Forms 等应用程序时),Browsabl...

C# OnMeasureItem

1. **整体功能概述**   - `OnMeasureItem` 是一个在Wi...

c# Invalidate、Refresh、Refreshitem、Refreshitems的功能

Invalidate方法功能概述Invalidate方法主要用于使控件的特定区域(整个控件或部分区域...

C# Graphics文本抗锯齿

g.TextRenderingHint = TextRenderingHint....

C# using与多重using

1. using 语句概述在 C# 中,using 语句主要用于确保实现了 IDisposable...

C# TextRenderer.MeasureText

TextRenderer.MeasureText是System.Windows.Forms命名空间中...