myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");
怎样把这个myAL发送给winform应用程序,还有winform应用程序怎么接收并还原成ArrayList对象?
请教,谢谢!
ArrayList 类
使用大小可按需动态增加的数组实现 IList 接口。
命名空间:System.Collections
程序集:mscorlib(在 mscorlib.dll 中)
语法
Visual Basic(声明)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class ArrayList
Implements IList, ICollection, IEnumerable, ICloneable
Visual Basic(用法)
Dim instance As ArrayList
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class ArrayList : IList, ICollection, IEnumerable,
ICloneable
C++
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class ArrayList : IList, ICollection, IEnumerable,
ICloneable
J#
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public class ArrayList implements IList, ICollection,
IEnumerable, ICloneable
JScript
SerializableAttribute
ComVisibleAttribute(true)
public class ArrayList implements IList, ICollection,
IEnumerable, ICloneable
备注
不保证会对 ArrayList 排序。在执行需要对 ArrayList 排序的操作(如 BinarySearch)之前,必须对 ArrayList 进行排序。
ArrayList 的容量是 ArrayList 可以保存的元素数。ArrayList 的默认初始容量为 0。随着元素添加到 ArrayList 中,容量会根据需要通过重新分配自动增加。可通过调用 TrimToSize 或通过显式设置 Capacity 属性减少容量。
使用整数索引可以访问此集合中的元素。此集合中的索引从零开始。
ArrayList 接受 空引用(在 Visual Basic 中为 Nothing) 作为有效值并且允许重复的元素。
示例
下面的代码示例演示如何创建并初始化 ArrayList 以及如何打印出其值。
Visual Basic 复制代码
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class SamplesArrayList
Public Shared Sub Main()
' Creates and initializes a new ArrayList.
Dim myAL As New ArrayList()
myAL.Add("Hello")
myAL.Add("World")
myAL.Add("!")
' Displays the properties and values of the ArrayList.
Console.WriteLine("myAL")
Console.WriteLine(" Count: {0}", myAL.Count)
Console.WriteLine(" Capacity: {0}", myAL.Capacity)
Console.Write(" Values:")
PrintValues(myAL)
End Sub
Public Shared Sub PrintValues(myList As IEnumerable)
Dim obj As [Object]
For Each obj In myList
Console.Write(" {0}", obj)
Next obj
Console.WriteLine()
End Sub 'PrintValues
End Class
' This code produces output similar to the following:
'
' myAL
' Count: 3
' Capacity: 4
' Values: Hello World !
C# 复制代码
using System;
using System.Collections;
public class SamplesArrayList {
public static void Main() {
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");
// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( " Count: {0}", myAL.Count );
Console.WriteLine( " Capacity: {0}", myAL.Capacity );
Console.Write( " Values:" );
PrintValues( myAL );
}
public static void PrintValues( IEnumerable myList ) {
foreach ( Object obj in myList )
Console.Write( " {0}", obj );
Console.WriteLine();
}
}
/*
This code produces output similar to the following:
myAL
Count: 3
Capacity: f
Values: Hello World !
*/
C++ 复制代码
using namespace System;
using namespace System::Collections;
void PrintValues( IEnumerable^ myList );
int main()
{
// Creates and initializes a new ArrayList.
ArrayList^ myAL = gcnew ArrayList;
myAL->Add( "Hello" );
myAL->Add( "World" );
myAL->Add( "!" );
// Displays the properties and values of the ArrayList.
Console::WriteLine( "myAL" );
Console::WriteLine( " Count: {0}", myAL->Count );
Console::WriteLine( " Capacity: {0}", myAL->Capacity );
Console::Write( " Values:" );
PrintValues( myAL );
}
void PrintValues( IEnumerable^ myList )
{
IEnumerator^ myEnum = myList->GetEnumerator();
while ( myEnum->MoveNext() )
{
Object^ obj = safe_cast<Object^>(myEnum->Current);
Console::Write( " {0}", obj );
}
Console::WriteLine();
}
/*
This code produces output similar to the following:
myAL
Count: 3
Capacity: 4
Values: Hello World !
*/
J# 复制代码
import System.*;
import System.Collections.*;
public class SamplesArrayList
{
public static void main(String[] args)
{
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");
// Displays the properties and values of the ArrayList.
Console.WriteLine("myAL");
Console.WriteLine(" Count: {0}", (Int32)myAL.get_Count());
Console.WriteLine(" Capacity: {0}", (Int32)myAL.get_Capacity());
Console.Write(" Values:");
PrintValues(myAL);
} //main
public static void PrintValues(IEnumerable myList)
{
IEnumerator objMyEnum = myList.GetEnumerator();
while (objMyEnum.MoveNext()) {
Object obj = objMyEnum.get_Current();
Console.Write(" {0}", obj);
}
Console.WriteLine();
} //PrintValues
} //SamplesArrayList
/*
This code produces output similar to the following:
myAL
Count: 3
Capacity: 4
Values: Hello World !
*/
JScript 复制代码
import System;
import System.Collections;
// Creates and initializes a new ArrayList.
var myAL : ArrayList = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");
// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( "\tCount: {0}", myAL.Count );
Console.WriteLine( "\tCapacity: {0}", myAL.Capacity );
Console.Write( "\tValues:" );
PrintValues( myAL );
function PrintValues( myList : IEnumerable ) {
var myEnumerator : System.Collections.IEnumerator = myList.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "\t{0}", myEnumerator.Current );
Console.WriteLine();
}
/*
This code produces output similar to the following:
myAL
Count: 3
Capacity: 4
Values: Hello World !
*/