InstallerCollection.CopyTo(Installer[], Int32) 方法

定义

从指定的索引处开始,将集合中的项复制到数组。Copies the items from the collection to an array, beginning at the specified index.

public:
 void CopyTo(cli::array <System::Configuration::Install::Installer ^> ^ array, int index);
public void CopyTo (System.Configuration.Install.Installer[] array, int index);
member this.CopyTo : System.Configuration.Install.Installer[] * int -> unit
Public Sub CopyTo (array As Installer(), index As Integer)

参数

array
Installer[]

要复制到的数组。The array to copy to.

index
Int32

数组的索引,在该处粘贴集合。The index of the array at which to paste the collection.

示例

下面的示例演示CopyToInstallerCollection类的方法。The following example demonstrates the CopyTo method of the InstallerCollection class. 它创建AssemblyInstaller MyAssembly1.exeMyAssembly2.exe的实例。It creates AssemblyInstaller instances for MyAssembly1.exe and MyAssembly2.exe. 这些实例将被添加到TransactedInstaller中。These instances are added to a TransactedInstaller. 要安装的程序集的名称显示在控制台上。The names of the assemblies to be installed are displayed on the console. 安装过程将同时MyAssembly1.exe安装和。 MyAssembly2.exeThe installation process installs both MyAssembly1.exe and MyAssembly2.exe.

TransactedInstaller^ myTransactedInstaller = gcnew TransactedInstaller;
AssemblyInstaller^ myAssemblyInstaller;
InstallContext^ myInstallContext;

// Create an instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller =
   gcnew AssemblyInstaller( "MyAssembly1.exe",nullptr );

// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller->Installers->Add( myAssemblyInstaller );

// Create an instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller =
   gcnew AssemblyInstaller( "MyAssembly2.exe",nullptr );

// Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller->Installers->Add( myAssemblyInstaller );

array<Installer^>^ myInstallers =
   gcnew array<Installer^>(myTransactedInstaller->Installers->Count);

myTransactedInstaller->Installers->CopyTo( myInstallers, 0 );
// Print the assemblies to be installed.
Console::WriteLine( "Printing all assemblies to be installed -" );
for ( int i = 0; i < myInstallers->Length; i++ )
{
   if ( dynamic_cast<AssemblyInstaller^>( myInstallers[ i ] ) )
   {
      Console::WriteLine( "{0} {1}", i + 1, ( (AssemblyInstaller^)( myInstallers[ i ]) )->Path );
   }
}
 TransactedInstaller myTransactedInstaller = new TransactedInstaller();
 AssemblyInstaller myAssemblyInstaller;
 InstallContext myInstallContext;

 // Create an instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
 myAssemblyInstaller =
    new AssemblyInstaller("MyAssembly1.exe", null);

 // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
 myTransactedInstaller.Installers.Add(myAssemblyInstaller);

 // Create an instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
 myAssemblyInstaller =
    new AssemblyInstaller("MyAssembly2.exe", null);

 // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
 myTransactedInstaller.Installers.Add(myAssemblyInstaller);

 Installer[] myInstallers =
    new Installer[myTransactedInstaller.Installers.Count];

 myTransactedInstaller.Installers.CopyTo(myInstallers, 0);
 // Print the assemblies to be installed.
 Console.WriteLine("Printing all assemblies to be installed -");
 for(int i = 0; i < myInstallers.Length; i++)
 {
    if((myInstallers[i].GetType()).Equals(typeof(AssemblyInstaller)))
    {
       Console.WriteLine("{0} {1}", i + 1,
          ((AssemblyInstaller)myInstallers[i]).Path);
    }
 }
Dim myTransactedInstaller As New TransactedInstaller()
Dim myAssemblyInstaller As AssemblyInstaller
Dim myInstallContext As InstallContext

' Create an instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
myAssemblyInstaller = New AssemblyInstaller("MyAssembly1.exe", Nothing)

' Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Add(myAssemblyInstaller)

' Create an instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
myAssemblyInstaller = New AssemblyInstaller("MyAssembly2.exe", Nothing)

' Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
myTransactedInstaller.Installers.Add(myAssemblyInstaller)

Dim myInstallers(myTransactedInstaller.Installers.Count-1) As Installer

myTransactedInstaller.Installers.CopyTo(myInstallers, 0)
' Print the assemblies to be installed.
Console.WriteLine("Printing all assemblies to be installed -")
Dim i As Integer
For i = 0 To myInstallers.Length - 1
   If myInstallers(i).GetType().Equals(GetType(AssemblyInstaller)) Then
      Console.WriteLine("{0} {1}", i + 1, CType(myInstallers(i), AssemblyInstaller).Path)
   End If
Next i

适用于