ObjectParameterCollection.CopyTo(ObjectParameter[], Int32) Method

Definition

Allows the parameters in the collection to be copied into a supplied array, starting with the object at the specified index.

C#
public void CopyTo(System.Data.Objects.ObjectParameter[] array, int index);

Parameters

array
ObjectParameter[]

The array into which to copy the parameters.

index
Int32

The index in the array at which to start copying the parameters.

Implements

Examples

This example copies the parameters into the specified array.

C#
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE contact FROM AdventureWorksEntities.Contacts
        AS contact WHERE contact.LastName = @ln
        AND contact.FirstName = @fn";

    ObjectQuery<Contact> contactQuery =
        new ObjectQuery<Contact>(queryString, context);

    // Add parameters to the collection.
    contactQuery.Parameters.Add(new ObjectParameter("ln", "Adams"));
    contactQuery.Parameters.Add(new ObjectParameter("fn", "Frances"));

    ObjectParameterCollection objectParameterCollection =
        contactQuery.Parameters;
    ObjectParameter[] objectParameterArray =
        new ObjectParameter[objectParameterCollection.Count];

    objectParameterCollection.CopyTo(objectParameterArray, 0);

    // Iterate through the ObjectParameter array.
    for (int i = 0; i < objectParameterArray.Length; i++)
    {
        Console.WriteLine("Name: {0} Type: {1} Value: {2}",
            objectParameterArray[i].Name,
            objectParameterArray[i].ParameterType,
            objectParameterArray[i].Value);
    }
}

Applies to

Proizvod Verzije
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1